| Flutter Impeller |

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
8 #include "impeller/renderer/backend/vulkan/texture_source_vk.h"
9 #include "impeller/renderer/backend/vulkan/vk.h"
10 #include "impeller/renderer/backend/vulkan/yuv_conversion_vk.h"
11 #include "impeller/toolkit/android/hardware_buffer.h"
12
13 #include <android/hardware_buffer.h>
14 #include <android/hardware_buffer_jni.h>
15
16 namespace impeller {
17
18 class ContextVK;
19
20 //------------------------------------------------------------------------------
21 /// @brief A texture source that wraps an instance of AHardwareBuffer.
22 ///
23 /// The formats and conversions supported by Android Hardware
24 /// Buffers are a superset of those supported by Impeller (and
25 /// Vulkan for that matter). Impeller and Vulkan descriptors
26 /// obtained from the these texture sources are advisory and it
27 /// usually isn't possible to create copies of images and image
28 /// views held in these texture sources using the inferred
29 /// descriptors. The objects are meant to be used directly (either
30 /// as render targets or sources for sampling), not copied.
31 ///
32 class AHBTextureSourceVK final : public TextureSourceVK {
33 public:
34 AHBTextureSourceVK(const std::shared_ptr<Context>& context,
35 struct AHardwareBuffer* hardware_buffer,
36 const AHardwareBuffer_Desc& hardware_buffer_desc);
37
38 AHBTextureSourceVK(const std::shared_ptr<Context>& context,
39 std::unique_ptr<android::HardwareBuffer> backing_store,
40 bool is_swapchain_image);
41
42 // |TextureSourceVK|
43 ~AHBTextureSourceVK() override;
44
45 // |TextureSourceVK|
46 vk::Image GetImage() const override;
47
48 // |TextureSourceVK|
49 vk::ImageView GetImageView() const override;
50
51 // |TextureSourceVK|
52 vk::ImageView GetRenderTargetView() const override;
53
54 bool IsValid() const;
55
56 // |TextureSourceVK|
57 bool IsSwapchainImage() const override;
58
59 // |TextureSourceVK|
60 std::shared_ptr<YUVConversionVK> GetYUVConversion() const override;
61
62 const android::HardwareBuffer* GetBackingStore() const;
63
64 private:
65 std::unique_ptr<android::HardwareBuffer> backing_store_;
66 vk::UniqueDeviceMemory device_memory_ = {};
67 vk::UniqueImage image_ = {};
68 vk::UniqueImageView image_view_ = {};
69 std::shared_ptr<YUVConversionVK> yuv_conversion_ = {};
70 bool needs_yuv_conversion_ = false;
71 bool is_swapchain_image_ = false;
72 bool is_valid_ = false;
73
74 AHBTextureSourceVK(const AHBTextureSourceVK&) = delete;
75
76 AHBTextureSourceVK& operator=(const AHBTextureSourceVK&) = delete;
77 };
78
79 } // namespace impeller
80
81 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_ANDROID_AHB_TEXTURE_SOURCE_VK_H_
impeller::AHBTextureSourceVK
A texture source that wraps an instance of AHardwareBuffer.
Definition: ahb_texture_source_vk.h:32
impeller::AHBTextureSourceVK::IsSwapchainImage
bool IsSwapchainImage() const override
Determines if swapchain image. That is, an image used as the root render target.
Definition: ahb_texture_source_vk.cc:430
impeller::AHBTextureSourceVK::GetImage
vk::Image GetImage() const override
Get the image handle for this texture source.
Definition: ahb_texture_source_vk.cc:415
impeller::AHBTextureSourceVK::IsValid
bool IsValid() const
Definition: ahb_texture_source_vk.cc:410
impeller::AHBTextureSourceVK::GetBackingStore
const android::HardwareBuffer * GetBackingStore() const
Definition: ahb_texture_source_vk.cc:439
impeller::AHBTextureSourceVK::GetYUVConversion
std::shared_ptr< YUVConversionVK > GetYUVConversion() const override
When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary t...
Definition: ahb_texture_source_vk.cc:435
impeller::AHBTextureSourceVK::AHBTextureSourceVK
AHBTextureSourceVK(const std::shared_ptr< Context > &context, struct AHardwareBuffer *hardware_buffer, const AHardwareBuffer_Desc &hardware_buffer_desc)
Definition: ahb_texture_source_vk.cc:309
impeller::AHBTextureSourceVK::~AHBTextureSourceVK
~AHBTextureSourceVK() override
impeller::AHBTextureSourceVK::GetImageView
vk::ImageView GetImageView() const override
Retrieve the image view used for sampling/blitting/compute with this texture source.
Definition: ahb_texture_source_vk.cc:420
impeller::AHBTextureSourceVK::GetRenderTargetView
vk::ImageView GetRenderTargetView() const override
Retrieve the image view used for render target attachments with this texture source.
Definition: ahb_texture_source_vk.cc:425
impeller::TextureSourceVK
Abstract base class that represents a vkImage and an vkImageView.
Definition: texture_source_vk.h:33
impeller::android::HardwareBuffer
A wrapper for AHardwareBuffer https://developer.android.com/ndk/reference/group/a-hardware-buffer.
Definition: hardware_buffer.h:89
hardware_buffer.h
impeller
Definition: allocation.cc:12
texture_source_vk.h
vk.h
yuv_conversion_vk.h