| 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 | SetCachedFrameData (const FramebufferAndRenderPass &data, SampleCount sample_count)
const FramebufferAndRenderPass & | GetCachedFrameData (SampleCount sample_count) 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 309 of file ahb_texture_source_vk.cc.

313 : TextureSourceVK(ToTextureDescriptor(ahb_desc)) {
314 if (!p_context) {
315 return;
316 }
317
318 const auto& context = ContextVK::Cast(*p_context);
319 const auto& device = context.GetDevice();
320 const auto& physical_device = context.GetPhysicalDevice();
321
322 AHBProperties ahb_props;
323
324 if (device.getAndroidHardwareBufferPropertiesANDROID(ahb, &ahb_props.get()) !=
325 vk::Result::eSuccess) {
326 VALIDATION_LOG << "Could not determine properties of the Android hardware "
327 "buffer.";
328 return;
329 }
330
331 const auto& ahb_format =
332 ahb_props.get<vk::AndroidHardwareBufferFormatPropertiesANDROID>();
333
334 // Create an image to refer to our external image.
335 auto image =
336 CreateVKImageWrapperForAndroidHarwareBuffer(device, ahb_props, ahb_desc);
337 if (!image) {
338 return;
339 }
340
341 // Create a device memory allocation to refer to our external image.
342 auto device_memory = ImportVKDeviceMemoryFromAndroidHarwareBuffer(
343 device, physical_device, image.get(), ahb, ahb_props);
344 if (!device_memory) {
345 return;
346 }
347
348 // Bind the image to the image memory.
349 if (auto result = device.bindImageMemory(image.get(), device_memory.get(), 0);
350 result != vk::Result::eSuccess) {
351 VALIDATION_LOG << "Could not bind external device memory to image : "
352 << vk::to_string(result);
353 return;
354 }
355
356 // Figure out how to perform YUV conversions.
357 needs_yuv_conversion_ = ahb_format.format == vk::Format::eUndefined ||
358 RequiresYCBCRConversion(ahb_format.format);
359 std::shared_ptr<YUVConversionVK> yuv_conversion;
360 if (needs_yuv_conversion_) {
361 yuv_conversion = CreateYUVConversion(context, ahb_props);
362 if (!yuv_conversion || !yuv_conversion->IsValid()) {
363 return;
364 }
365 }
366
367 // Create image view for the newly created image.
368 auto image_view = CreateVKImageView(device, //
369 image.get(), //
370 yuv_conversion, //
371 ahb_props, //
372 ahb_desc //
373 );
374 if (!image_view) {
375 return;
376 }
377
378 device_memory_ = std::move(device_memory);
379 image_ = std::move(image);
380 yuv_conversion_ = std::move(yuv_conversion);
381 image_view_ = std::move(image_view);
382
383 #ifdef IMPELLER_DEBUG
384 context.SetDebugName(device_memory_.get(), "AHB Device Memory");
385 context.SetDebugName(image_.get(), "AHB Image");
386 if (yuv_conversion_) {
387 context.SetDebugName(yuv_conversion_->GetConversion(),
388 "AHB YUV Conversion");
389 }
390 context.SetDebugName(image_view_.get(), "AHB ImageView");
391 #endif // IMPELLER_DEBUG
392
393 is_valid_ = true;
394 }
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
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::BackendCast< ContextVK, Context >::Cast(), 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 396 of file ahb_texture_source_vk.cc.

400 : AHBTextureSourceVK(context,
401 backing_store->GetHandle(),
402 backing_store->GetAndroidDescriptor()) {
403 backing_store_ = std::move(backing_store);
404 is_swapchain_image_ = is_swapchain_image;
405 }
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

## ◆ ~AHBTextureSourceVK()

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

## Member Function Documentation

## ◆ GetBackingStore()

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

Definition at line 439 of file ahb_texture_source_vk.cc.

439 {
440 return backing_store_.get();
441 }

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

415 {
416 return image_.get();
417 }

## ◆ 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 420 of file ahb_texture_source_vk.cc.

420 {
421 return image_view_.get();
422 }

## ◆ 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 425 of file ahb_texture_source_vk.cc.

425 {
426 return image_view_.get();
427 }

## ◆ 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 435 of file ahb_texture_source_vk.cc.

435 {
436 return needs_yuv_conversion_ ? yuv_conversion_ : nullptr;
437 }

Referenced by impeller::android::testing::TEST().

## ◆ 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 430 of file ahb_texture_source_vk.cc.

430 {
431 return is_swapchain_image_;
432 }

## ◆ IsValid()

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

Definition at line 410 of file ahb_texture_source_vk.cc.

410 {
411 return is_valid_;
412 }

Referenced by impeller::android::testing::TEST().

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