| Flutter Impeller |

Public Member Functions | List of all members
impeller::AHBTextureSourceVK Class Referencefinal

A texture source that wraps an instance of AHardwareBuffer. More...

`#include <ahb_texture_source_vk.h>`

Inheritance diagram for impeller::AHBTextureSourceVK:

## Public Member Functions
| AHBTextureSourceVK (const std::shared_ptr< Context > &context, struct AHardwareBuffer *hardware_buffer, const AHardwareBuffer_Desc &hardware_buffer_desc)
| AHBTextureSourceVK (const std::shared_ptr< Context > &context, std::unique_ptr< android::HardwareBuffer > backing_store, bool is_swapchain_image)
| ~AHBTextureSourceVK () override
vk::Image | GetImage () const override
| Get the image handle for this texture source. More...
vk::ImageView | GetImageView () const override
| Retrieve the image view used for sampling/blitting/compute with this texture source. More...
vk::ImageView | GetRenderTargetView () const override
| Retrieve the image view used for render target attachments with this texture source. More...
bool | IsValid () const
bool | IsSwapchainImage () const override
| Determines if swapchain image. That is, an image used as the root render target. More...
std::shared_ptr< YUVConversionVK > | GetYUVConversion () const override
| When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary to setup custom samplers. This accessor provides this conversion if one is present. Most texture source have none. More...
const android::HardwareBuffer * | GetBackingStore () const
Public Member Functions inherited from impeller::TextureSourceVK
virtual | ~TextureSourceVK ()
const TextureDescriptor & | GetTextureDescriptor () const
| Gets the texture descriptor for this image source. More...
fml::Status | SetLayout (const BarrierVK &barrier) const
| Encodes the layout transition `barrier` to `barrier.cmd_buffer` for the image. More...
vk::ImageLayout | SetLayoutWithoutEncoding (vk::ImageLayout layout) const
| Store the layout of the image. More...
vk::ImageLayout | GetLayout () const
| Get the last layout assigned to the TextureSourceVK. More...
void | SetCachedFramebuffer (const SharedHandleVK< vk::Framebuffer > &framebuffer)
void | SetCachedRenderPass (const SharedHandleVK< vk::RenderPass > &render_pass)
SharedHandleVK< vk::Framebuffer > | GetCachedFramebuffer () const
SharedHandleVK< vk::RenderPass > | GetCachedRenderPass () const

## Additional Inherited Members
Protected Member Functions inherited from impeller::TextureSourceVK
| TextureSourceVK (TextureDescriptor desc)
Protected Attributes inherited from impeller::TextureSourceVK
const TextureDescriptor | desc_

## Detailed Description

A texture source that wraps an instance of AHardwareBuffer.

            The formats and conversions supported by Android Hardware
            Buffers are a superset of those supported by Impeller (and
            Vulkan for that matter). Impeller and Vulkan descriptors
            obtained from the these texture sources are advisory and it
            usually isn't possible to create copies of images and image
            views held in these texture sources using the inferred
            descriptors. The objects are meant to be used directly (either
            as render targets or sources for sampling), not copied.

Definition at line 32 of file ahb_texture_source_vk.h.

## Constructor & Destructor Documentation

## ◆ AHBTextureSourceVK() [1/2]

impeller::AHBTextureSourceVK::AHBTextureSourceVK | ( | const std::shared_ptr< Context > & | context,
|  | struct AHardwareBuffer * | hardware_buffer,
|  | const AHardwareBuffer_Desc & | hardware_buffer_desc
| ) |  |

Definition at line 294 of file ahb_texture_source_vk.cc.

298 : TextureSourceVK(ToTextureDescriptor(ahb_desc)) {
299 if (!p_context) {
300 return;
301 }
302
303 const auto& context = ContextVK::Cast(*p_context);
304 const auto& device = context.GetDevice();
305 const auto& physical_device = context.GetPhysicalDevice();
306
307 AHBProperties ahb_props;
308
309 if (device.getAndroidHardwareBufferPropertiesANDROID(ahb, &ahb_props.get()) !=
310 vk::Result::eSuccess) {
311 VALIDATION_LOG << "Could not determine properties of the Android hardware "
312 "buffer.";
313 return;
314 }
315
316 const auto& ahb_format =
317 ahb_props.get<vk::AndroidHardwareBufferFormatPropertiesANDROID>();
318
319 // Create an image to refer to our external image.
320 auto image =
321 CreateVKImageWrapperForAndroidHarwareBuffer(device, ahb_props, ahb_desc);
322 if (!image) {
323 return;
324 }
325
326 // Create a device memory allocation to refer to our external image.
327 auto device_memory = ImportVKDeviceMemoryFromAndroidHarwareBuffer(
328 device, physical_device, image.get(), ahb, ahb_props);
329 if (!device_memory) {
330 return;
331 }
332
333 // Bind the image to the image memory.
334 if (auto result = device.bindImageMemory(image.get(), device_memory.get(), 0);
335 result != vk::Result::eSuccess) {
336 VALIDATION_LOG << "Could not bind external device memory to image : "
337 << vk::to_string(result);
338 return;
339 }
340
341 // Figure out how to perform YUV conversions.
342 auto yuv_conversion = CreateYUVConversion(context, ahb_props);
343 if (!yuv_conversion || !yuv_conversion->IsValid()) {
344 return;
345 }
346
347 // Create image view for the newly created image.
348 auto image_view = CreateVKImageView(device, //
349 image.get(), //
350 yuv_conversion->GetConversion(), //
351 ahb_props, //
352 ahb_desc //
353 );
354 if (!image_view) {
355 return;
356 }
357
358 needs_yuv_conversion_ = ahb_format.format == vk::Format::eUndefined;
359 device_memory_ = std::move(device_memory);
360 image_ = std::move(image);
361 yuv_conversion_ = std::move(yuv_conversion);
362 image_view_ = std::move(image_view);
363
364 #ifdef IMPELLER_DEBUG
365 context.SetDebugName(device_memory_.get(), "AHB Device Memory");
366 context.SetDebugName(image_.get(), "AHB Image");
367 context.SetDebugName(yuv_conversion_->GetConversion(), "AHB YUV Conversion");
368 context.SetDebugName(image_view_.get(), "AHB ImageView");
369 #endif // IMPELLER_DEBUG
370
371 is_valid_ = true;
372 }
impeller::BackendCast< ContextVK, Context >::Cast
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
impeller::TextureSourceVK::TextureSourceVK
TextureSourceVK(TextureDescriptor desc)
Definition: texture_source_vk.cc:9
impeller::AHBProperties
vk::StructureChain< vk::AndroidHardwareBufferPropertiesANDROID, vk::AndroidHardwareBufferFormatPropertiesANDROID > AHBProperties
Definition: ahb_texture_source_vk.cc:18
impeller::CreateYUVConversion
static std::shared_ptr< YUVConversionVK > CreateYUVConversion(const ContextVK &context, const AHBProperties &ahb_props)
Definition: ahb_texture_source_vk.cc:141
impeller::CreateVKImageWrapperForAndroidHarwareBuffer
static vk::UniqueImage CreateVKImageWrapperForAndroidHarwareBuffer(const vk::Device &device, const AHBProperties &ahb_props, const AHardwareBuffer_Desc &ahb_desc)
Definition: ahb_texture_source_vk.cc:20
impeller::CreateVKImageView
static vk::UniqueImageView CreateVKImageView(const vk::Device &device, const vk::Image &image, const vk::SamplerYcbcrConversion &yuv_conversion, const AHBProperties &ahb_props, const AHardwareBuffer_Desc &ahb_desc)
Definition: ahb_texture_source_vk.cc:179
impeller::ToTextureDescriptor
static TextureDescriptor ToTextureDescriptor(const AHardwareBuffer_Desc &ahb_desc)
Definition: ahb_texture_source_vk.cc:272
impeller::ImportVKDeviceMemoryFromAndroidHarwareBuffer
static vk::UniqueDeviceMemory ImportVKDeviceMemoryFromAndroidHarwareBuffer(const vk::Device &device, const vk::PhysicalDevice &physical_device, const vk::Image &image, struct AHardwareBuffer *hardware_buffer, const AHBProperties &ahb_props)
Definition: ahb_texture_source_vk.cc:97
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::BackendCast< ContextVK, Context >::Cast(), impeller::CreateVKImageView(), impeller::CreateVKImageWrapperForAndroidHarwareBuffer(), impeller::CreateYUVConversion(), impeller::ImportVKDeviceMemoryFromAndroidHarwareBuffer(), and VALIDATION_LOG.

## ◆ AHBTextureSourceVK() [2/2]

impeller::AHBTextureSourceVK::AHBTextureSourceVK | ( | const std::shared_ptr< Context > & | context,
|  | std::unique_ptr< android::HardwareBuffer > | backing_store,
|  | bool | is_swapchain_image
| ) |  |

Definition at line 374 of file ahb_texture_source_vk.cc.

378 : AHBTextureSourceVK(context,
379 backing_store->GetHandle(),
380 backing_store->GetAndroidDescriptor()) {
381 backing_store_ = std::move(backing_store);
382 is_swapchain_image_ = is_swapchain_image;
383 }
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:294

## ◆ ~AHBTextureSourceVK()

impeller::AHBTextureSourceVK::~AHBTextureSourceVK | ( |  | ) |
| override default

## Member Function Documentation

## ◆ GetBackingStore()

const android::HardwareBuffer * impeller::AHBTextureSourceVK::GetBackingStore | ( |  | ) | const

Definition at line 417 of file ahb_texture_source_vk.cc.

417 {
418 return backing_store_.get();
419 }

Referenced by impeller::glvk::CreateEGLImageFromAHBTexture().

## ◆ GetImage()

vk::Image impeller::AHBTextureSourceVK::GetImage | ( |  | ) | const
| override virtual

Get the image handle for this texture source.

Returns
  The image.

Implements impeller::TextureSourceVK.

Definition at line 393 of file ahb_texture_source_vk.cc.

393 {
394 return image_.get();
395 }

## ◆ GetImageView()

vk::ImageView impeller::AHBTextureSourceVK::GetImageView | ( |  | ) | const
| override virtual

Retrieve the image view used for sampling/blitting/compute with this texture source.

Returns
  The image view.

Implements impeller::TextureSourceVK.

Definition at line 398 of file ahb_texture_source_vk.cc.

398 {
399 return image_view_.get();
400 }

## ◆ GetRenderTargetView()

vk::ImageView impeller::AHBTextureSourceVK::GetRenderTargetView | ( |  | ) | const
| override virtual

Retrieve the image view used for render target attachments with this texture source.

ImageViews used as render target attachments cannot have any mip levels. In cases where we want to generate mipmaps with the result of this texture, we need to create multiple image views.

Returns
  The render target view.

Implements impeller::TextureSourceVK.

Definition at line 403 of file ahb_texture_source_vk.cc.

403 {
404 return image_view_.get();
405 }

## ◆ GetYUVConversion()

std::shared_ptr< YUVConversionVK > impeller::AHBTextureSourceVK::GetYUVConversion | ( |  | ) | const
| override virtual

When sampling from textures whose formats are not known to Vulkan, a custom conversion is necessary to setup custom samplers. This accessor provides this conversion if one is present. Most texture source have none.

Returns
  The sampler conversion.

Reimplemented from impeller::TextureSourceVK.

Definition at line 413 of file ahb_texture_source_vk.cc.

413 {
414 return needs_yuv_conversion_ ? yuv_conversion_ : nullptr;
415 }

## ◆ IsSwapchainImage()

bool impeller::AHBTextureSourceVK::IsSwapchainImage | ( |  | ) | const
| override virtual

Determines if swapchain image. That is, an image used as the root render target.

Returns
  Whether or not this is a swapchain image.

Implements impeller::TextureSourceVK.

Definition at line 408 of file ahb_texture_source_vk.cc.

408 {
409 return is_swapchain_image_;
410 }

## ◆ IsValid()

bool impeller::AHBTextureSourceVK::IsValid | ( |  | ) | const

Definition at line 388 of file ahb_texture_source_vk.cc.

388 {
389 return is_valid_;
390 }

The documentation for this class was generated from the following files:

- impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.h
- impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.cc