Flutter Engine
The Flutter Engine
GrVkSamplerYcbcrConversion.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
13
16 if (!gpu->vkCaps().supportsYcbcrConversion()) {
17 return nullptr;
18 }
19
22
23#ifdef SK_BUILD_FOR_ANDROID
24 VkExternalFormatANDROID externalFormat;
25 if (info.fExternalFormat) {
26 // Format must not be specified for external images.
29 externalFormat.pNext = nullptr;
30 externalFormat.externalFormat = info.fExternalFormat;
31 SkASSERT(ycbcrCreateInfo.pNext == nullptr);
32 ycbcrCreateInfo.pNext = &externalFormat;
33 }
34#else
35 // External images are supported only on Android.
36 SkASSERT(!info.fExternalFormat);
37#endif
38
39 if (!info.fExternalFormat) {
41 }
42
43 VkSamplerYcbcrConversion conversion;
45 GR_VK_CALL_RESULT(gpu, result, CreateSamplerYcbcrConversion(gpu->device(), &ycbcrCreateInfo,
46 nullptr, &conversion));
47 if (result != VK_SUCCESS) {
48 return nullptr;
49 }
50
51 return new GrVkSamplerYcbcrConversion(gpu, conversion, GenerateKey(info));
52}
53
54void GrVkSamplerYcbcrConversion::freeGPUData() const {
55 SkASSERT(fYcbcrConversion);
56 GR_VK_CALL(fGpu->vkInterface(), DestroySamplerYcbcrConversion(fGpu->device(),
57 fYcbcrConversion, nullptr));
58}
59
61 const skgpu::VulkanYcbcrConversionInfo& ycbcrInfo) {
62 SkASSERT(static_cast<int>(ycbcrInfo.fYcbcrModel <= 7));
63 static const int kRangeShift = 3;
64 SkASSERT(static_cast<int>(ycbcrInfo.fYcbcrRange) <= 1);
65 static const int kXChromaOffsetShift = kRangeShift + 1;
66 SkASSERT(static_cast<int>(ycbcrInfo.fXChromaOffset) <= 1);
67 static const int kYChromaOffsetShift = kXChromaOffsetShift + 1;
68 SkASSERT(static_cast<int>(ycbcrInfo.fXChromaOffset) <= 1);
69 static const int kChromaFilterShift = kYChromaOffsetShift + 1;
70 SkASSERT(static_cast<int>(ycbcrInfo.fChromaFilter) <= 1);
71 static const int kReconShift = kChromaFilterShift + 1;
72 SkASSERT(static_cast<int>(ycbcrInfo.fForceExplicitReconstruction) <= 1);
73 static const int kCompRShift = kReconShift + 1;
74 static const int kCompGShift = kCompRShift + 3;
75 static const int kCompBShift = kCompGShift + 3;
76 static const int kCompAShift = kCompBShift + 3;
77 SkASSERT(static_cast<int>(ycbcrInfo.fComponents.r <= 6) &&
78 static_cast<int>(ycbcrInfo.fComponents.g <= 6) &&
79 static_cast<int>(ycbcrInfo.fComponents.b <= 6) &&
80 static_cast<int>(ycbcrInfo.fComponents.a <= 6));
81 static_assert(kCompAShift <= 17);
82
83 uint32_t ycbcrKey = static_cast<uint32_t>(ycbcrInfo.fYcbcrModel);
84 ycbcrKey |= (static_cast<uint32_t>(ycbcrInfo.fYcbcrRange) << kRangeShift);
85 ycbcrKey |= (static_cast<uint32_t>(ycbcrInfo.fXChromaOffset) << kXChromaOffsetShift);
86 ycbcrKey |= (static_cast<uint32_t>(ycbcrInfo.fYChromaOffset) << kYChromaOffsetShift);
87 ycbcrKey |= (static_cast<uint32_t>(ycbcrInfo.fChromaFilter) << kChromaFilterShift);
88 ycbcrKey |= (static_cast<uint32_t>(ycbcrInfo.fForceExplicitReconstruction) << kReconShift);
89 ycbcrKey |= (static_cast<uint32_t>(ycbcrInfo.fComponents.r) << kCompRShift);
90 ycbcrKey |= (static_cast<uint32_t>(ycbcrInfo.fComponents.g) << kCompGShift);
91 ycbcrKey |= (static_cast<uint32_t>(ycbcrInfo.fComponents.b) << kCompBShift);
92 ycbcrKey |= (static_cast<uint32_t>(ycbcrInfo.fComponents.a) << kCompAShift);
93
94 return Key{ycbcrInfo.fFormat, ycbcrInfo.fExternalFormat, ycbcrKey};
95}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define GR_VK_CALL(IFACE, X)
Definition: GrVkUtil.h:24
#define GR_VK_CALL_RESULT(GPU, RESULT, X)
Definition: GrVkUtil.h:35
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool supportsYcbcrConversion() const
Definition: GrVkCaps.h:153
const GrVkCaps & vkCaps() const
Definition: GrVkGpu.h:61
const skgpu::VulkanInterface * vkInterface() const
Definition: GrVkGpu.h:60
VkDevice device() const
Definition: GrVkGpu.h:71
static GrVkSamplerYcbcrConversion * Create(GrVkGpu *gpu, const skgpu::VulkanYcbcrConversionInfo &)
static SK_END_REQUIRE_DENSE Key GenerateKey(const skgpu::VulkanYcbcrConversionInfo &ycbcrInfo)
GAsyncResult * result
void SetupSamplerYcbcrConversionInfo(VkSamplerYcbcrConversionCreateInfo *outInfo, const VulkanYcbcrConversionInfo &conversionInfo)
VkComponentSwizzle r
Definition: vulkan_core.h:3460
VkComponentSwizzle a
Definition: vulkan_core.h:3463
VkComponentSwizzle g
Definition: vulkan_core.h:3461
VkComponentSwizzle b
Definition: vulkan_core.h:3462
VkStructureType sType
VkSamplerYcbcrRange fYcbcrRange
Definition: VulkanTypes.h:104
VkSamplerYcbcrModelConversion fYcbcrModel
Definition: VulkanTypes.h:103
VkComponentMapping fComponents
Definition: VulkanTypes.h:115
VkResult
Definition: vulkan_core.h:140
@ VK_SUCCESS
Definition: vulkan_core.h:141
@ VK_FORMAT_UNDEFINED
Definition: vulkan_core.h:1459
@ VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID
Definition: vulkan_core.h:647