Commit 67893ecf authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

Support more formats for Vulkan

Bug: 838899
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel
Change-Id: I5e8cfd0ad6fc86c6e4e1dcc5983f372a3a3142b3
Reviewed-on: https://chromium-review.googlesource.com/1160770Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581209}
parent 935e1732
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "components/viz/service/gl/gpu_service_impl.h" #include "components/viz/service/gl/gpu_service_impl.h"
#include "gpu/command_buffer/common/swap_buffers_complete_params.h" #include "gpu/command_buffer/common/swap_buffers_complete_params.h"
#include "gpu/command_buffer/service/scheduler.h" #include "gpu/command_buffer/service/scheduler.h"
#include "ui/gfx/skia_util.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h" #include "ui/gl/gl_context.h"
#include "ui/gl/gl_gl_api_implementation.h" #include "ui/gl/gl_gl_api_implementation.h"
...@@ -324,18 +325,8 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImage( ...@@ -324,18 +325,8 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImage(
*metadata.backend_format.getGLTarget()); *metadata.backend_format.getGLTarget());
} else { } else {
#if BUILDFLAG(ENABLE_VULKAN) #if BUILDFLAG(ENABLE_VULKAN)
VkFormat format = VK_FORMAT_UNDEFINED; metadata.backend_format = GrBackendFormat::MakeVk(
switch (metadata.color_type) { gfx::SkColorTypeToVkFormat(metadata.color_type));
case kRGBA_8888_SkColorType:
format = VK_FORMAT_R8G8B8A8_UNORM;
break;
case kBGRA_8888_SkColorType:
format = VK_FORMAT_B8G8R8A8_UNORM;
break;
default:
NOTREACHED();
}
metadata.backend_format = GrBackendFormat::MakeVk(format);
#else #else
NOTREACHED(); NOTREACHED();
#endif #endif
...@@ -414,7 +405,7 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass( ...@@ -414,7 +405,7 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass(
SkSurfaceProps surface_props(flags, SkSurfaceProps::kLegacyFontHost_InitType); SkSurfaceProps surface_props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
int msaa_sample_count = 0; int msaa_sample_count = 0;
SkColorType color_type = SkColorType color_type =
ResourceFormatToClosestSkColorType(true /*gpu_compositing */, format); ResourceFormatToClosestSkColorType(true /* gpu_compositing */, format);
SkImageInfo image_info = SkImageInfo image_info =
SkImageInfo::Make(surface_size.width(), surface_size.height(), color_type, SkImageInfo::Make(surface_size.width(), surface_size.height(), color_type,
kPremul_SkAlphaType, nullptr /* color_space */); kPremul_SkAlphaType, nullptr /* color_space */);
...@@ -431,7 +422,8 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass( ...@@ -431,7 +422,8 @@ SkCanvas* SkiaOutputSurfaceImpl::BeginPaintRenderPass(
GL_TEXTURE_2D); GL_TEXTURE_2D);
} else { } else {
#if BUILDFLAG(ENABLE_VULKAN) #if BUILDFLAG(ENABLE_VULKAN)
backend_format = GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM); backend_format =
GrBackendFormat::MakeVk(gfx::SkColorTypeToVkFormat(color_type));
#else #else
NOTREACHED(); NOTREACHED();
#endif #endif
...@@ -479,7 +471,8 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImageFromRenderPass( ...@@ -479,7 +471,8 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImageFromRenderPass(
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(recorder_); DCHECK(recorder_);
SkColorType color_type = kBGRA_8888_SkColorType; SkColorType color_type =
ResourceFormatToClosestSkColorType(true /* gpu_compositing */, format);
GrBackendFormat backend_format; GrBackendFormat backend_format;
if (!gpu_service_->is_using_vulkan()) { if (!gpu_service_->is_using_vulkan()) {
...@@ -489,11 +482,10 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImageFromRenderPass( ...@@ -489,11 +482,10 @@ sk_sp<SkImage> SkiaOutputSurfaceImpl::MakePromiseSkImageFromRenderPass(
backend_format = GrBackendFormat::MakeGL( backend_format = GrBackendFormat::MakeGL(
gl::GetInternalFormat(version_info, texture_storage_format), gl::GetInternalFormat(version_info, texture_storage_format),
GL_TEXTURE_2D); GL_TEXTURE_2D);
color_type =
ResourceFormatToClosestSkColorType(true /*gpu_compositing */, format);
} else { } else {
#if BUILDFLAG(ENABLE_VULKAN) #if BUILDFLAG(ENABLE_VULKAN)
backend_format = GrBackendFormat::MakeVk(VK_FORMAT_B8G8R8A8_UNORM); backend_format =
GrBackendFormat::MakeVk(gfx::SkColorTypeToVkFormat(color_type));
#else #else
NOTREACHED(); NOTREACHED();
#endif #endif
......
...@@ -37,6 +37,7 @@ jumbo_component("geometry_skia") { ...@@ -37,6 +37,7 @@ jumbo_component("geometry_skia") {
] ]
deps = [ deps = [
"//base", "//base",
"//gpu/vulkan:buildflags",
"//skia", "//skia",
"//ui/gfx/geometry", "//ui/gfx/geometry",
] ]
......
...@@ -3,9 +3,11 @@ include_rules = [ ...@@ -3,9 +3,11 @@ include_rules = [
"+cc/base", "+cc/base",
"+cc/paint", "+cc/paint",
"+device/vr/buildflags/buildflags.h", "+device/vr/buildflags/buildflags.h",
"+gpu/vulkan/buildflags.h",
"+skia/ext", "+skia/ext",
"+third_party/harfbuzz-ng", "+third_party/harfbuzz-ng",
"+third_party/skia", "+third_party/skia",
"+third_party/vulkan",
"+ui/ios", "+ui/ios",
"-testing/gmock", "-testing/gmock",
......
...@@ -157,4 +157,37 @@ float HarfBuzzUnitsToFloat(int value) { ...@@ -157,4 +157,37 @@ float HarfBuzzUnitsToFloat(int value) {
return kFloatToHbRatio * value; return kFloatToHbRatio * value;
} }
#if BUILDFLAG(ENABLE_VULKAN)
VkFormat SkColorTypeToVkFormat(SkColorType color_type) {
switch (color_type) {
case kUnknown_SkColorType:
break;
case kAlpha_8_SkColorType:
return VK_FORMAT_R8_UNORM;
case kRGB_565_SkColorType:
return VK_FORMAT_R5G6B5_UNORM_PACK16;
case kARGB_4444_SkColorType:
return VK_FORMAT_B4G4R4A4_UNORM_PACK16;
case kRGBA_8888_SkColorType:
return VK_FORMAT_R8G8B8A8_UNORM; // or VK_FORMAT_R8G8B8A8_SRGB
case kRGB_888x_SkColorType: // Skia doesn't support it yet.
break;
case kBGRA_8888_SkColorType:
return VK_FORMAT_B8G8R8A8_UNORM; // or VK_FORMAT_B8G8R8A8_SRGB
case kRGBA_1010102_SkColorType:
return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
case kGray_8_SkColorType:
return VK_FORMAT_R8_UNORM;
case kRGBA_F16_SkColorType:
return VK_FORMAT_R16G16B16A16_SFLOAT;
case kRGBA_F32_SkColorType:
return VK_FORMAT_R32G32B32A32_SFLOAT;
case kRGB_101010x_SkColorType: // Skia doesn't support it yet.
break;
}
NOTREACHED();
return VK_FORMAT_UNDEFINED;
}
#endif
} // namespace gfx } // namespace gfx
...@@ -8,12 +8,18 @@ ...@@ -8,12 +8,18 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "gpu/vulkan/buildflags.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkRect.h"
#include "ui/gfx/geometry/quad_f.h" #include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/gfx_export.h" #include "ui/gfx/gfx_export.h"
#if BUILDFLAG(ENABLE_VULKAN)
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/vulkan/include/vulkan/vulkan.h"
#endif
class SkBitmap; class SkBitmap;
class SkMatrix; class SkMatrix;
...@@ -62,6 +68,11 @@ GFX_EXPORT SkScalar HarfBuzzUnitsToSkiaScalar(int value); ...@@ -62,6 +68,11 @@ GFX_EXPORT SkScalar HarfBuzzUnitsToSkiaScalar(int value);
// Converts an hb_position_t to a float. // Converts an hb_position_t to a float.
GFX_EXPORT float HarfBuzzUnitsToFloat(int value); GFX_EXPORT float HarfBuzzUnitsToFloat(int value);
#if BUILDFLAG(ENABLE_VULKAN)
// Converts a Skia color type to a compitable VkFormat
GFX_EXPORT VkFormat SkColorTypeToVkFormat(SkColorType color_type);
#endif
} // namespace gfx } // namespace gfx
#endif // UI_GFX_SKIA_UTIL_H_ #endif // UI_GFX_SKIA_UTIL_H_
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