| Flutter Impeller |

yuv_conversion_vk.h
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
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_YUV_CONVERSION_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_YUV_CONVERSION_VK_H_
7
8 #include <unordered_map>
9
10 #include "flutter/fml/build_config.h"
11 #include "impeller/base/comparable.h"
12 #include "impeller/base/thread.h"
13 #include "impeller/core/sampler.h"
14 #include "impeller/renderer/backend/vulkan/sampler_vk.h"
15 #include "impeller/renderer/backend/vulkan/shared_object_vk.h"
16 #include "impeller/renderer/backend/vulkan/vk.h"
17
18 namespace impeller {
19
20 //------------------------------------------------------------------------------
21 /// A descriptor used to create a new YUV conversion in a conversion library.
22 ///
23 using YUVConversionDescriptorVK =
24 vk::StructureChain<vk::SamplerYcbcrConversionCreateInfo
25 #if FML_OS_ANDROID
26 // For VK_ANDROID_external_memory_android_hardware_buffer
27 ,
28 vk::ExternalFormatANDROID
29 #endif // FML_OS_ANDROID
30 >;
31
32 class YUVConversionLibraryVK;
33
34 //------------------------------------------------------------------------------
35 /// @brief It is sometimes necessary to deal with formats not native to
36 /// Vulkan. In such cases, extra information is necessary to access
37 /// images. A YUV conversion object is needed in such instances.
38 ///
39 /// There are usually only a handful of viable conversions in a
40 /// given context. However, due to the way the Vulkan spec. treats
41 /// "identically defined" conversions, only a single conversion
42 /// object is valid for an equivalent `YUVConversionDescriptorVK`.
43 /// Because of this restriction, it is not possible to just create a
44 /// conversion from a descriptor (as the underlying handles will be
45 /// equivalent but different). Instead, a conversion may only be
46 /// obtained from a conversion library. Libraries handle hashing and
47 /// caching conversions by descriptor. Caller can find a library on
48 /// the top-level context. They may not create their own (the
49 /// constructor is private).
50 ///
51 class YUVConversionVK final {
52 public:
53 ~YUVConversionVK();
54
55 YUVConversionVK(const YUVConversionVK&) = delete;
56
57 YUVConversionVK& operator=(const YUVConversionVK&) = delete;
58
59 //----------------------------------------------------------------------------
60 /// @return `true` if this conversion is valid for use with images and
61 /// samplers.
62 ///
63 bool IsValid() const;
64
65 //----------------------------------------------------------------------------
66 /// @brief Get the descriptor used to create this conversion.
67 ///
68 const YUVConversionDescriptorVK& GetDescriptor() const;
69
70 //----------------------------------------------------------------------------
71 /// @return The Vulkan handle of the YUV conversion.
72 ///
73 vk::SamplerYcbcrConversion GetConversion() const;
74
75 private:
76 friend class YUVConversionLibraryVK;
77
78 YUVConversionDescriptorVK chain_;
79 vk::UniqueSamplerYcbcrConversion conversion_;
80
81 YUVConversionVK(const vk::Device& device,
82 const YUVConversionDescriptorVK& chain);
83 };
84
85 struct YUVConversionDescriptorVKHash {
86 std::size_t operator()(const YUVConversionDescriptorVK& object) const;
87 };
88
89 struct YUVConversionDescriptorVKEqual {
90 bool operator()(const YUVConversionDescriptorVK& lhs,
91 const YUVConversionDescriptorVK& rhs) const;
92 };
93
94 struct ImmutableSamplerKeyVK : public Comparable<ImmutableSamplerKeyVK> {
95 SamplerDescriptor sampler;
96 YUVConversionDescriptorVK yuv_conversion;
97
98 explicit ImmutableSamplerKeyVK(const SamplerVK& sampler);
99
100 // |Comparable<ImmutableSamplerKey>|
101 std::size_t GetHash() const override;
102
103 // |Comparable<ImmutableSamplerKey>|
104 bool IsEqual(const ImmutableSamplerKeyVK& other) const override;
105 };
106
107 } // namespace impeller
108
109 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_YUV_CONVERSION_VK_H_
impeller::ImmutableSamplerKeyVK
Definition: yuv_conversion_vk.h:94
shared_object_vk.h
impeller::ImmutableSamplerKeyVK::ImmutableSamplerKeyVK
ImmutableSamplerKeyVK(const SamplerVK &sampler)
Definition: yuv_conversion_vk.cc:103
sampler.h
impeller::YUVConversionVK::IsValid
bool IsValid() const
Definition: yuv_conversion_vk.cc:29
impeller::SamplerVK
Definition: sampler_vk.h:18
impeller::YUVConversionVK::GetConversion
vk::SamplerYcbcrConversion GetConversion() const
Definition: yuv_conversion_vk.cc:33
vk.h
impeller::YUVConversionDescriptorVKHash
Definition: yuv_conversion_vk.h:85
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:14
impeller::YUVConversionVK::YUVConversionVK
YUVConversionVK(const YUVConversionVK &)=delete
impeller::ImmutableSamplerKeyVK::IsEqual
bool IsEqual(const ImmutableSamplerKeyVK &other) const override
Definition: yuv_conversion_vk.cc:110
impeller::YUVConversionVK::GetDescriptor
const YUVConversionDescriptorVK & GetDescriptor() const
Get the descriptor used to create this conversion.
Definition: yuv_conversion_vk.cc:38
impeller::YUVConversionVK::~YUVConversionVK
~YUVConversionVK()
impeller::YUVConversionVK::operator=
YUVConversionVK & operator=(const YUVConversionVK &)=delete
impeller::YUVConversionVK
It is sometimes necessary to deal with formats not native to Vulkan. In such cases,...
Definition: yuv_conversion_vk.h:51
impeller::ImmutableSamplerKeyVK::GetHash
std::size_t GetHash() const override
Definition: yuv_conversion_vk.cc:116
impeller::YUVConversionLibraryVK
Due the way the Vulkan spec. treats "identically defined" conversions, creating two conversion with i...
Definition: yuv_conversion_library_vk.h:26
impeller::ImmutableSamplerKeyVK::yuv_conversion
YUVConversionDescriptorVK yuv_conversion
Definition: yuv_conversion_vk.h:96
impeller::YUVConversionDescriptorVKEqual
Definition: yuv_conversion_vk.h:89
impeller::YUVConversionDescriptorVKHash::operator()
std::size_t operator()(const YUVConversionDescriptorVK &object) const
Definition: yuv_conversion_vk.cc:42
impeller::Comparable
Definition: comparable.h:29
comparable.h
sampler_vk.h
impeller::YUVConversionDescriptorVKEqual::operator()
bool operator()(const YUVConversionDescriptorVK &lhs, const YUVConversionDescriptorVK &rhs) const
Definition: yuv_conversion_vk.cc:68
impeller::ImmutableSamplerKeyVK::sampler
SamplerDescriptor sampler
Definition: yuv_conversion_vk.h:95
impeller::YUVConversionDescriptorVK
vk::StructureChain< vk::SamplerYcbcrConversionCreateInfo > YUVConversionDescriptorVK
Definition: yuv_conversion_vk.h:30
thread.h
impeller
Definition: allocation.cc:12