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

Public Member Functions

 AHBTextureSourceVK (const std::shared_ptr< ContextVK > &context, struct AHardwareBuffer *hardware_buffer, const AHardwareBuffer_Desc &hardware_buffer_desc)
 
 ~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.
 
- 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 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 34 of file ahb_texture_source_vk.h.

Constructor & Destructor Documentation

◆ AHBTextureSourceVK()

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

Definition at line 282 of file ahb_texture_source_vk.cc.

287 if (!context) {
288 VALIDATION_LOG << "Invalid context.";
289 return;
290 }
291
292 const auto& device = context->GetDevice();
293 const auto& physical_device = context->GetPhysicalDevice();
294
295 AHBProperties ahb_props;
296
297 if (device.getAndroidHardwareBufferPropertiesANDROID(ahb, &ahb_props.get()) !=
298 vk::Result::eSuccess) {
299 VALIDATION_LOG << "Could not determine properties of the Android hardware "
300 "buffer.";
301 return;
302 }
303
304 const auto& ahb_format =
305 ahb_props.get<vk::AndroidHardwareBufferFormatPropertiesANDROID>();
306
307 // Create an image to refer to our external image.
308 auto image =
310 if (!image) {
311 return;
312 }
313
314 // Create a device memory allocation to refer to our external image.
316 device, physical_device, image.get(), ahb, ahb_props);
317 if (!device_memory) {
318 return;
319 }
320
321 // Bind the image to the image memory.
322 if (auto result = device.bindImageMemory(image.get(), device_memory.get(), 0);
323 result != vk::Result::eSuccess) {
324 VALIDATION_LOG << "Could not bind external device memory to image : "
325 << vk::to_string(result);
326 return;
327 }
328
329 // Figure out how to perform YUV conversions.
330 auto yuv_conversion = CreateYUVConversion(*context, ahb_props);
331 if (!yuv_conversion || !yuv_conversion->IsValid()) {
332 return;
333 }
334
335 // Create image view for the newly created image.
336 auto image_view = CreateVKImageView(device, //
337 image.get(), //
338 yuv_conversion->GetConversion(), //
339 ahb_props, //
340 ahb_desc //
341 );
342 if (!image_view) {
343 return;
344 }
345
346 needs_yuv_conversion_ = ahb_format.format == vk::Format::eUndefined;
347 device_memory_ = std::move(device_memory);
348 image_ = std::move(image);
349 yuv_conversion_ = std::move(yuv_conversion);
350 image_view_ = std::move(image_view);
351
352#ifdef IMPELLER_DEBUG
353 context->SetDebugName(device_memory_.get(), "AHB Device Memory");
354 context->SetDebugName(image_.get(), "AHB Image");
355 context->SetDebugName(yuv_conversion_->GetConversion(), "AHB YUV Conversion");
356 context->SetDebugName(image_view_.get(), "AHB ImageView");
357#endif // IMPELLER_DEBUG
358
359 is_valid_ = true;
360}
TextureSourceVK(TextureDescriptor desc)
T * get() const
Definition SkRefCnt.h:303
VkPhysicalDevice physical_device
Definition main.cc:51
VkDevice device
Definition main.cc:53
sk_sp< SkImage > image
Definition examples.cpp:29
GAsyncResult * result
vk::StructureChain< vk::AndroidHardwareBufferPropertiesANDROID, vk::AndroidHardwareBufferFormatPropertiesANDROID > AHBProperties
static vk::UniqueImage CreateVKImageWrapperForAndroidHarwareBuffer(const vk::Device &device, const AHBProperties &ahb_props, const AHardwareBuffer_Desc &ahb_desc)
static std::shared_ptr< YUVConversionVK > CreateYUVConversion(const ContextVK &context, const AHBProperties &ahb_props)
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)
static TextureDescriptor ToTextureDescriptor(const AHardwareBuffer_Desc &ahb_desc)
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)
#define VALIDATION_LOG
Definition validation.h:73

◆ ~AHBTextureSourceVK()

impeller::AHBTextureSourceVK::~AHBTextureSourceVK ( )
overridedefault

Member Function Documentation

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

370 {
371 return image_.get();
372}

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

375 {
376 return image_view_.get();
377}

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

380 {
381 return image_view_.get();
382}

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

390 {
391 return needs_yuv_conversion_ ? yuv_conversion_ : nullptr;
392}

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

385 {
386 return false;
387}

◆ IsValid()

bool impeller::AHBTextureSourceVK::IsValid ( ) const

Definition at line 365 of file ahb_texture_source_vk.cc.

365 {
366 return is_valid_;
367}

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