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

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

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

## ◆ ~AHBTextureSourceVK()

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

## Member Function Documentation

## ◆ GetBackingStore()

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

Definition at line 438 of file ahb_texture_source_vk.cc.

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

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

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

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

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

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

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

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

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

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

429 {
430 return is_swapchain_image_;
431 }

## ◆ IsValid()

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

Definition at line 409 of file ahb_texture_source_vk.cc.

409 {
410 return is_valid_;
411 }

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