Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
ahb_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_ANDROID_AHB_TEXTURE_SOURCE_VK_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_ANDROID_AHB_TEXTURE_SOURCE_VK_H_
7
13
15#include <android/hardware_buffer_jni.h>
16
17namespace impeller {
18
19class ContextVK;
20
21//------------------------------------------------------------------------------
22/// @brief A texture source that wraps an instance of AHardwareBuffer.
23///
24/// The formats and conversions supported by Android Hardware
25/// Buffers are a superset of those supported by Impeller (and
26/// Vulkan for that matter). Impeller and Vulkan descriptors
27/// obtained from the these texture sources are advisory and it
28/// usually isn't possible to create copies of images and image
29/// views held in these texture sources using the inferred
30/// descriptors. The objects are meant to be used directly (either
31/// as render targets or sources for sampling), not copied.
32///
33class AHBTextureSourceVK final : public TextureSourceVK {
34 public:
35 AHBTextureSourceVK(const std::shared_ptr<Context>& context,
36 struct AHardwareBuffer* hardware_buffer,
37 const AHardwareBuffer_Desc& hardware_buffer_desc);
38
39 AHBTextureSourceVK(const std::shared_ptr<Context>& context,
40 std::unique_ptr<android::HardwareBuffer> backing_store,
41 bool is_swapchain_image);
42
43 // |TextureSourceVK|
44 ~AHBTextureSourceVK() override;
45
46 // |TextureSourceVK|
47 vk::Image GetImage() const override;
48
49 // |TextureSourceVK|
50 vk::ImageView GetImageView() const override;
51
52 // |TextureSourceVK|
53 vk::ImageView GetRenderTargetView(uint32_t mip_level,
54 uint32_t array_layer) const override;
55
56 bool IsValid() const;
57
58 // |TextureSourceVK|
59 bool IsSwapchainImage() const override;
60
61 // |TextureSourceVK|
62 std::shared_ptr<YUVConversionVK> GetYUVConversion() const override;
63
65
66 using AHBProperties = vk::StructureChain<
67 // For VK_ANDROID_external_memory_android_hardware_buffer
68 vk::AndroidHardwareBufferPropertiesANDROID,
69 // For VK_ANDROID_external_memory_android_hardware_buffer
70 vk::AndroidHardwareBufferFormatPropertiesANDROID>;
71
72 using ImageViewInfo = vk::StructureChain<vk::ImageViewCreateInfo,
73 // Core in 1.1
74 vk::SamplerYcbcrConversionInfo>;
75
76 /// Create a VkImage that wraps an Android hardware buffer.
78 const vk::Device& device,
79 const AHBProperties& ahb_props,
80 const AHardwareBuffer_Desc& ahb_desc);
81
82 /// Create a VkImageViewCreateInfo that matches the properties of an Android
83 /// hardware buffer.
85 const vk::Image& image,
86 const std::shared_ptr<YUVConversionVK>& yuv_conversion_wrapper,
87 const AHBProperties& ahb_props,
88 const AHardwareBuffer_Desc& ahb_desc);
89
90 private:
91 std::weak_ptr<DeviceHolderVK> device_holder_;
92 std::unique_ptr<android::HardwareBuffer> backing_store_;
93 vk::UniqueDeviceMemory device_memory_ = {};
94 vk::UniqueImage image_ = {};
95 vk::UniqueImageView image_view_ = {};
96 std::shared_ptr<YUVConversionVK> yuv_conversion_ = {};
97 bool needs_yuv_conversion_ = false;
98 bool is_swapchain_image_ = false;
99 bool is_valid_ = false;
100
101 AHBTextureSourceVK(const AHBTextureSourceVK&) = delete;
102
103 AHBTextureSourceVK& operator=(const AHBTextureSourceVK&) = delete;
104};
105
106} // namespace impeller
107
108#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_ANDROID_AHB_TEXTURE_SOURCE_VK_H_
A texture source that wraps an instance of AHardwareBuffer.
vk::StructureChain< vk::ImageViewCreateInfo, vk::SamplerYcbcrConversionInfo > ImageViewInfo
vk::ImageView GetRenderTargetView(uint32_t mip_level, uint32_t array_layer) const override
Retrieve the image view used to attach a specific subresource of this texture as a render target.
bool IsSwapchainImage() const override
Determines if swapchain image. That is, an image used as the root render target.
vk::Image GetImage() const override
Get the image handle for this texture source.
static vk::UniqueImage CreateVKImageWrapperForAndroidHarwareBuffer(const vk::Device &device, const AHBProperties &ahb_props, const AHardwareBuffer_Desc &ahb_desc)
Create a VkImage that wraps an Android hardware buffer.
const android::HardwareBuffer * GetBackingStore() const
std::shared_ptr< YUVConversionVK > GetYUVConversion() const override
When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary t...
vk::StructureChain< vk::AndroidHardwareBufferPropertiesANDROID, vk::AndroidHardwareBufferFormatPropertiesANDROID > AHBProperties
AHBTextureSourceVK(const std::shared_ptr< Context > &context, struct AHardwareBuffer *hardware_buffer, const AHardwareBuffer_Desc &hardware_buffer_desc)
vk::ImageView GetImageView() const override
Retrieve the image view used for sampling/blitting/compute with this texture source.
static ImageViewInfo CreateImageViewInfo(const vk::Image &image, const std::shared_ptr< YUVConversionVK > &yuv_conversion_wrapper, const AHBProperties &ahb_props, const AHardwareBuffer_Desc &ahb_desc)
Abstract base class that represents a vkImage and an vkImageView.
A wrapper for AHardwareBuffer https://developer.android.com/ndk/reference/group/a-hardware-buffer.
FlutterVulkanImage * image
VkDevice device
Definition main.cc:69
std::shared_ptr< ContextGLES > context