Flutter Engine
 
Loading...
Searching...
No Matches
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:
impeller::TextureSourceVK

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.
 
vk::ImageView GetImageView () const override
 Retrieve the image view used for sampling/blitting/compute with this texture source.
 
vk::ImageView GetRenderTargetView () const override
 Retrieve the image view used for render target attachments with this texture source.
 
bool IsValid () const
 
bool IsSwapchainImage () const override
 Determines if swapchain image. That is, an image used as the root render target.
 
std::shared_ptr< YUVConversionVKGetYUVConversion () 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.
 
const android::HardwareBufferGetBackingStore () const
 
- Public Member Functions inherited from impeller::TextureSourceVK
virtual ~TextureSourceVK ()
 
const TextureDescriptorGetTextureDescriptor () const
 Gets the texture descriptor for this image source.
 
fml::Status SetLayout (const BarrierVK &barrier) const
 Encodes the layout transition barrier to barrier.cmd_buffer for the image.
 
vk::ImageLayout SetLayoutWithoutEncoding (vk::ImageLayout layout) const
 Store the layout of the image.
 
vk::ImageLayout GetLayout () const
 Get the last layout assigned to the TextureSourceVK.
 
void SetCachedFrameData (const FramebufferAndRenderPass &data, SampleCount sample_count)
 
const FramebufferAndRenderPassGetCachedFrameData (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}
static ContextVK & Cast(Context &base)
TextureSourceVK(TextureDescriptor desc)
FlutterVulkanImage * image
VkPhysicalDevice physical_device
Definition main.cc:67
VkDevice device
Definition main.cc:69
#define VALIDATION_LOG
Definition validation.h:91

References impeller::BackendCast< ContextVK, Context >::Cast(), device, image, physical_device, 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}
AHBTextureSourceVK(const std::shared_ptr< Context > &context, struct AHardwareBuffer *hardware_buffer, const AHardwareBuffer_Desc &hardware_buffer_desc)

◆ ~AHBTextureSourceVK()

impeller::AHBTextureSourceVK::~AHBTextureSourceVK ( )
overridedefault

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
overridevirtual

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
overridevirtual

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

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

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

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

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

◆ 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 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(), and impeller::android::testing::TEST().


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