Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
VulkanSamplerYcbcrConversion.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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
14
15namespace skgpu::graphite {
16
18 const VulkanSharedContext* context,
19 const VulkanYcbcrConversionInfo& conversionInfo) {
20 if (!context->vulkanCaps().supportsYcbcrConversion()) {
21 return nullptr;
22 }
23
25 skgpu::SetupSamplerYcbcrConversionInfo(&ycbcrCreateInfo, conversionInfo);
26
27#ifdef SK_BUILD_FOR_ANDROID
28 VkExternalFormatANDROID externalFormat;
29 if (conversionInfo.fExternalFormat) {
30 // Format must not be specified for external images.
31 SkASSERT(conversionInfo.fFormat == VK_FORMAT_UNDEFINED);
33 externalFormat.pNext = nullptr;
34 externalFormat.externalFormat = conversionInfo.fExternalFormat;
35 SkASSERT(ycbcrCreateInfo.pNext == nullptr);
36 ycbcrCreateInfo.pNext = &externalFormat;
37 }
38#else
39 // External images are supported only on Android.
40 SkASSERT(!conversionInfo.fExternalFormat);
41#endif
42
43 if (!conversionInfo.fExternalFormat) {
44 SkASSERT(conversionInfo.fFormat != VK_FORMAT_UNDEFINED);
45 }
46
47 VkSamplerYcbcrConversion conversion;
49 VULKAN_CALL_RESULT(context,
50 result,
51 CreateSamplerYcbcrConversion(
52 context->device(), &ycbcrCreateInfo, nullptr, &conversion));
53 if (result != VK_SUCCESS) {
54 return nullptr;
55 }
57 new VulkanSamplerYcbcrConversion(context, conversion));
58}
59
61 const VulkanSharedContext* context, const VulkanYcbcrConversionInfo& info) {
63
64 bool useExternalFormat = info.fFormat == VK_FORMAT_UNDEFINED;
65 // 2 uint32s needed for the external format or 1 for a known VkFormat. 1 uint32 can store all
66 // other differentiating ycbcr information.
67 static const int num32DataCnt = useExternalFormat ? 3 : 2;
69 GraphiteResourceKey::Builder builder(&key, kType, num32DataCnt, Shareable::kYes);
70
71 int i = 0;
72 if (useExternalFormat) {
73 builder[i++] = (uint32_t)(info.fExternalFormat << 32);
74 builder[i++] = (uint32_t)info.fExternalFormat;
75 } else {
76 builder[i++] = info.fFormat;
77 }
78 builder[i++] = info.nonFormatInfoAsUInt32();
79 SkASSERT(i == num32DataCnt);
80
81 builder.finish();
82 return key;
83}
84
85VulkanSamplerYcbcrConversion::VulkanSamplerYcbcrConversion(
86 const VulkanSharedContext* context, VkSamplerYcbcrConversion ycbcrConversion)
87 : Resource(context,
90 /*gpuMemorySize=*/0,
91 /*label=*/"VulkanSamplerYcbcrConversion")
92 , fYcbcrConversion (ycbcrConversion) {}
93
95 auto sharedContext = static_cast<const VulkanSharedContext*>(this->sharedContext());
96 SkASSERT(fYcbcrConversion != VK_NULL_HANDLE);
97 VULKAN_CALL(sharedContext->interface(),
98 DestroySamplerYcbcrConversion(sharedContext->device(), fYcbcrConversion, nullptr));
99}
100
101} // namespace skgpu::graphite
102
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SkASSERT(cond)
Definition SkAssert.h:116
#define VULKAN_CALL(IFACE, X)
#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X)
const GraphiteResourceKey & key() const
Definition Resource.h:153
const SharedContext * sharedContext() const
Definition Resource.h:187
bool supportsYcbcrConversion() const
Definition VulkanCaps.h:86
static GraphiteResourceKey MakeYcbcrConversionKey(const VulkanSharedContext *, const VulkanYcbcrConversionInfo &)
static sk_sp< VulkanSamplerYcbcrConversion > Make(const VulkanSharedContext *, const VulkanYcbcrConversionInfo &)
const VulkanCaps & vulkanCaps() const
GAsyncResult * result
uint32_t ResourceType
Budgeted
Definition GpuTypes.h:35
void SetupSamplerYcbcrConversionInfo(VkSamplerYcbcrConversionCreateInfo *outInfo, const VulkanYcbcrConversionInfo &conversionInfo)
VkResult
@ VK_SUCCESS
#define VK_NULL_HANDLE
Definition vulkan_core.h:46
@ VK_FORMAT_UNDEFINED
@ VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID