Flutter Engine
The Flutter Engine
texture_source_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_TEXTURE_SOURCE_VK_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_TEXTURE_SOURCE_VK_H_
7
8#include "flutter/fml/status.h"
16#include "vulkan/vulkan_handles.hpp"
17
18namespace impeller {
19
20//------------------------------------------------------------------------------
21/// @brief Abstract base class that represents a vkImage and an
22/// vkImageView.
23///
24/// This is intended to be used with an impeller::TextureVK. Example
25/// implementations represent swapchain images, uploaded textures,
26/// Android Hardware Buffer backend textures, etc...
27///
29 public:
31
32 //----------------------------------------------------------------------------
33 /// @brief Gets the texture descriptor for this image source.
34 ///
35 /// @warning Texture descriptors from texture sources whose capabilities
36 /// are a superset of those that can be expressed with Vulkan
37 /// (like Android Hardware Buffer) are inferred. Stuff like size,
38 /// mip-counts, types is reliable. So use these descriptors as
39 /// advisory. Creating copies of texture sources from these
40 /// descriptors is usually not possible and depends on the
41 /// allocator used.
42 ///
43 /// @return The texture descriptor.
44 ///
46
47 //----------------------------------------------------------------------------
48 /// @brief Get the image handle for this texture source.
49 ///
50 /// @return The image.
51 ///
52 virtual vk::Image GetImage() const = 0;
53
54 //----------------------------------------------------------------------------
55 /// @brief Retrieve the image view used for sampling/blitting/compute
56 /// with this texture source.
57 ///
58 /// @return The image view.
59 ///
60 virtual vk::ImageView GetImageView() const = 0;
61
62 //----------------------------------------------------------------------------
63 /// @brief Retrieve the image view used for render target attachments
64 /// with this texture source.
65 ///
66 /// ImageViews used as render target attachments cannot have any
67 /// mip levels. In cases where we want to generate mipmaps with
68 /// the result of this texture, we need to create multiple image
69 /// views.
70 ///
71 /// @return The render target view.
72 ///
73 virtual vk::ImageView GetRenderTargetView() const = 0;
74
75 //----------------------------------------------------------------------------
76 /// @brief Encodes the layout transition `barrier` to
77 /// `barrier.cmd_buffer` for the image.
78 ///
79 /// The transition is from the layout stored via
80 /// `SetLayoutWithoutEncoding` to `barrier.new_layout`.
81 ///
82 /// @param[in] barrier The barrier.
83 ///
84 /// @return If the layout transition was successfully made.
85 ///
86 fml::Status SetLayout(const BarrierVK& barrier) const;
87
88 //----------------------------------------------------------------------------
89 /// @brief Store the layout of the image.
90 ///
91 /// This just is bookkeeping on the CPU, to actually set the
92 /// layout use `SetLayout`.
93 ///
94 /// @param[in] layout The new layout.
95 ///
96 /// @return The old layout.
97 ///
98 vk::ImageLayout SetLayoutWithoutEncoding(vk::ImageLayout layout) const;
99
100 //----------------------------------------------------------------------------
101 /// @brief Get the last layout assigned to the TextureSourceVK.
102 ///
103 /// This value is synchronized with the GPU via SetLayout so it
104 /// may not reflect the actual layout.
105 ///
106 /// @return The last known layout of the texture source.
107 ///
108 vk::ImageLayout GetLayout() const;
109
110 //----------------------------------------------------------------------------
111 /// @brief When sampling from textures whose formats are not known to
112 /// Vulkan, a custom conversion is necessary to setup custom
113 /// samplers. This accessor provides this conversion if one is
114 /// present. Most texture source have none.
115 ///
116 /// @return The sampler conversion.
117 ///
118 virtual std::shared_ptr<YUVConversionVK> GetYUVConversion() const;
119
120 //----------------------------------------------------------------------------
121 /// @brief Determines if swapchain image. That is, an image used as the
122 /// root render target.
123 ///
124 /// @return Whether or not this is a swapchain image.
125 ///
126 virtual bool IsSwapchainImage() const = 0;
127
128 // These methods should only be used by render_pass_vk.h
129
130 /// Store the last framebuffer object used with this texture.
131 ///
132 /// This field is only set if this texture is used as the resolve texture
133 /// of a render pass. By construction, this framebuffer should be compatible
134 /// with any future render passes.
136
137 /// Store the last render pass object used with this texture.
138 ///
139 /// This field is only set if this texture is used as the resolve texture
140 /// of a render pass. By construction, this framebuffer should be compatible
141 /// with any future render passes.
143
144 /// Retrieve the last framebuffer object used with this texture.
145 ///
146 /// May be nullptr if no previous framebuffer existed.
148
149 /// Retrieve the last render pass object used with this texture.
150 ///
151 /// May be nullptr if no previous render pass existed.
153
154 protected:
156
158
159 private:
162 mutable RWMutex layout_mutex_;
163 mutable vk::ImageLayout layout_ IPLR_GUARDED_BY(layout_mutex_) =
164 vk::ImageLayout::eUndefined;
165};
166
167} // namespace impeller
168
169#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_TEXTURE_SOURCE_VK_H_
Abstract base class that represents a vkImage and an vkImageView.
TextureSourceVK(TextureDescriptor desc)
void SetCachedRenderPass(const SharedHandleVK< vk::RenderPass > &render_pass)
virtual std::shared_ptr< YUVConversionVK > GetYUVConversion() const
When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary t...
virtual vk::ImageView GetRenderTargetView() const =0
Retrieve the image view used for render target attachments with this texture source.
virtual bool IsSwapchainImage() const =0
Determines if swapchain image. That is, an image used as the root render target.
const TextureDescriptor & GetTextureDescriptor() const
Gets the texture descriptor for this image source.
SharedHandleVK< vk::Framebuffer > GetCachedFramebuffer() const
virtual vk::ImageView GetImageView() const =0
Retrieve the image view used for sampling/blitting/compute with this texture source.
virtual vk::Image GetImage() const =0
Get the image handle for this texture source.
void SetCachedFramebuffer(const SharedHandleVK< vk::Framebuffer > &framebuffer)
SharedHandleVK< vk::RenderPass > GetCachedRenderPass() const
vk::ImageLayout GetLayout() const
Get the last layout assigned to the TextureSourceVK.
vk::ImageLayout SetLayoutWithoutEncoding(vk::ImageLayout layout) const
Store the layout of the image.
const TextureDescriptor desc_
fml::Status SetLayout(const BarrierVK &barrier) const
Encodes the layout transition barrier to barrier.cmd_buffer for the image.
CanvasImage Image
Definition: dart_ui.cc:55
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
fuchsia::ui::composition::LayoutInfo layout_
Defines an operations and memory access barrier on a resource.
Definition: barrier_vk.h:27
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...