Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
yuv_conversion_vk.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
12
13namespace impeller {
14
16 const std::shared_ptr<DeviceHolderVK>& device_holder,
17 const YUVConversionDescriptorVK& chain)
18 : device_holder_(device_holder), chain_(chain) {
19 auto conversion =
20 device_holder->GetDevice().createSamplerYcbcrConversionUnique(
21 chain_.get());
22 if (conversion.result != vk::Result::eSuccess) {
23 VALIDATION_LOG << "Could not create YUV conversion: "
24 << vk::to_string(conversion.result);
25 return;
26 }
27 conversion_ = std::move(conversion.value);
28}
29
30YUVConversionVK::~YUVConversionVK() {
31 if (auto device = device_holder_.lock(); !device) {
32 conversion_.release();
33 }
34}
35
36bool YUVConversionVK::IsValid() const {
37 return conversion_ && !!conversion_.get();
38}
39
40vk::SamplerYcbcrConversion YUVConversionVK::GetConversion() const {
41 return conversion_ ? conversion_.get()
42 : static_cast<vk::SamplerYcbcrConversion>(VK_NULL_HANDLE);
43}
44
45const YUVConversionDescriptorVK& YUVConversionVK::GetDescriptor() const {
46 return chain_;
47}
48
49std::size_t YUVConversionDescriptorVKHash::operator()(
50 const YUVConversionDescriptorVK& desc) const {
51 // Hashers in Vulkan HPP hash the pNext member which isn't what we want for
52 // these to be stable.
53 const auto& conv = desc.get();
54
55 std::size_t hash = fml::HashCombine(conv.format, //
56 conv.ycbcrModel, //
57 conv.ycbcrRange, //
58 conv.components.r, //
59 conv.components.g, //
60 conv.components.b, //
61 conv.components.a, //
62 conv.xChromaOffset, //
63 conv.yChromaOffset, //
64 conv.chromaFilter, //
65 conv.forceExplicitReconstruction //
66 );
67#if FML_OS_ANDROID
68 const auto external_format = desc.get<vk::ExternalFormatANDROID>();
69 fml::HashCombineSeed(hash, external_format.externalFormat);
70#endif // FML_OS_ANDROID
71
72 return hash;
73};
74
75bool YUVConversionDescriptorVKEqual::operator()(
76 const YUVConversionDescriptorVK& lhs_desc,
77 const YUVConversionDescriptorVK& rhs_desc) const {
78 // Default equality checks in Vulkan HPP checks pNext member members by
79 // pointer which isn't what we want.
80 {
81 const auto& lhs = lhs_desc.get();
82 const auto& rhs = rhs_desc.get();
83
84 if (lhs.format != rhs.format || //
85 lhs.ycbcrModel != rhs.ycbcrModel || //
86 lhs.ycbcrRange != rhs.ycbcrRange || //
87 lhs.components.r != rhs.components.r || //
88 lhs.components.g != rhs.components.g || //
89 lhs.components.b != rhs.components.b || //
90 lhs.components.a != rhs.components.a || //
91 lhs.xChromaOffset != rhs.xChromaOffset || //
92 lhs.yChromaOffset != rhs.yChromaOffset || //
93 lhs.chromaFilter != rhs.chromaFilter || //
94 lhs.forceExplicitReconstruction != rhs.forceExplicitReconstruction //
95 ) {
96 return false;
97 }
98 }
99#if FML_OS_ANDROID
100 {
101 const auto lhs = lhs_desc.get<vk::ExternalFormatANDROID>();
102 const auto rhs = rhs_desc.get<vk::ExternalFormatANDROID>();
103 return lhs.externalFormat == rhs.externalFormat;
104 }
105#else // FML_OS_ANDROID
106 return true;
107#endif // FML_OS_ANDROID
108}
109
110ImmutableSamplerKeyVK::ImmutableSamplerKeyVK(const SamplerVK& sampler)
111 : sampler(sampler.GetDescriptor()) {
112 if (const auto& conversion = sampler.GetYUVConversion()) {
113 yuv_conversion = conversion->GetDescriptor();
114 }
115}
116
122
127
128} // namespace impeller
const SamplerDescriptor & GetDescriptor() const
Definition sampler.cc:13
YUVConversionVK(const YUVConversionVK &)=delete
VkDevice device
Definition main.cc:69
constexpr std::size_t HashCombine()
constexpr void HashCombineSeed(std::size_t &seed, const Type &arg)
vk::StructureChain< vk::SamplerYcbcrConversionCreateInfo > YUVConversionDescriptorVK
bool IsEqual(const ImmutableSamplerKeyVK &other) const override
YUVConversionDescriptorVK yuv_conversion
std::size_t GetHash() const override
static uint64_t ToKey(const SamplerDescriptor &d)
#define VALIDATION_LOG
Definition validation.h:91