| 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 290 of file ahb_texture_source_vk.cc.

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

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 371 of file ahb_texture_source_vk.cc.

375 : AHBTextureSourceVK(context,
376 backing_store->GetHandle(),
377 backing_store->GetAndroidDescriptor()) {
378 backing_store_ = std::move(backing_store);
379 is_swapchain_image_ = is_swapchain_image;
380 }

## ◆ ~AHBTextureSourceVK()

impeller::AHBTextureSourceVK::~AHBTextureSourceVK | ( |  | ) |
| overridedefault

## Member Function Documentation

## ◆ GetBackingStore()

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

Definition at line 414 of file ahb_texture_source_vk.cc.

414 {
415 return backing_store_.get();
416 }

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

## ◆ GetImage()

vk::Image impeller::AHBTextureSourceVK::GetImage | ( |  | ) | const
| overridevirtual

Get the image handle for this texture source.

Returns
  The image.

Implements impeller::TextureSourceVK.

Definition at line 390 of file ahb_texture_source_vk.cc.

390 {
391 return image_.get();
392 }

## ◆ GetImageView()

vk::ImageView impeller::AHBTextureSourceVK::GetImageView | ( |  | ) | const
| overridevirtual

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

Returns
  The image view.

Implements impeller::TextureSourceVK.

Definition at line 395 of file ahb_texture_source_vk.cc.

395 {
396 return image_view_.get();
397 }

## ◆ GetRenderTargetView()

vk::ImageView impeller::AHBTextureSourceVK::GetRenderTargetView | ( |  | ) | const
| overridevirtual

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 400 of file ahb_texture_source_vk.cc.

400 {
401 return image_view_.get();
402 }

## ◆ GetYUVConversion()

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

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 410 of file ahb_texture_source_vk.cc.

410 {
411 return needs_yuv_conversion_ ? yuv_conversion_ : nullptr;
412 }

## ◆ IsSwapchainImage()

bool impeller::AHBTextureSourceVK::IsSwapchainImage | ( |  | ) | const
| overridevirtual

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 405 of file ahb_texture_source_vk.cc.

405 {
406 return is_swapchain_image_;
407 }

## ◆ IsValid()

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

Definition at line 385 of file ahb_texture_source_vk.cc.

385 {
386 return is_valid_;
387 }

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

impeller::TextureSourceVK::TextureSourceVK
TextureSourceVK(TextureDescriptor desc)
Definition: texture_source_vk.cc:9
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:290
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::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
impeller::CreateYUVConversion
static std::shared_ptr< YUVConversionVK > CreateYUVConversion(const ContextVK &context, const AHBProperties &ahb_props)
Definition: ahb_texture_source_vk.cc:141
impeller::ToTextureDescriptor
static TextureDescriptor ToTextureDescriptor(const AHardwareBuffer_Desc &ahb_desc)
Definition: ahb_texture_source_vk.cc:268
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
impeller::BackendCast< ContextVK, Context >::Cast
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
impeller::AHBProperties
vk::StructureChain< vk::AndroidHardwareBufferPropertiesANDROID, vk::AndroidHardwareBufferFormatPropertiesANDROID > AHBProperties
Definition: ahb_texture_source_vk.cc:18
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:175