| Flutter Impeller |

Public Types | Public Member Functions | Static Public Member Functions | List of all members
impeller::KHRSurfaceVK Class Referencefinal

`#include <khr_surface_vk.h>`

Inheritance diagram for impeller::KHRSurfaceVK:

## Public Types
using | SwapCallback = std::function< bool(void)>

## Public Member Functions
| ~KHRSurfaceVK () override
Public Member Functions inherited from impeller::Surface
| Surface ()
| Surface (const RenderTarget &target_desc)
virtual | ~Surface ()
const ISize & | GetSize () const
bool | IsValid () const
const RenderTarget & | GetTargetRenderPassDescriptor () const

## Static Public Member Functions
static std::unique_ptr< KHRSurfaceVK > | WrapSwapchainImage (const std::shared_ptr< Context > &context, std::shared_ptr< KHRSwapchainImageVK > &swapchain_image, SwapCallback swap_callback, bool enable_msaa=true)
| Wrap the swapchain image in a Surface, which provides the additional configuration required for usage as on onscreen render target by Impeller. More...

## Detailed Description

Definition at line 16 of file khr_surface_vk.h.

## Member Typedef Documentation

## ◆ SwapCallback

using impeller::KHRSurfaceVK::SwapCallback = std::function<bool(void)>

Definition at line 18 of file khr_surface_vk.h.

## Constructor & Destructor Documentation

## ◆ ~KHRSurfaceVK()

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

## Member Function Documentation

## ◆ WrapSwapchainImage()

std::unique_ptr< KHRSurfaceVK > impeller::KHRSurfaceVK::WrapSwapchainImage | ( | const std::shared_ptr< Context > & | context,
|  | std::shared_ptr< KHRSwapchainImageVK > & | swapchain_image,
|  | SwapCallback | swap_callback,
|  | bool | enable_msaa = `true`
| ) |  |
| static

Wrap the swapchain image in a Surface, which provides the additional configuration required for usage as on onscreen render target by Impeller.

This creates the associated MSAA and depth+stencil texture.

Definition at line 14 of file khr_surface_vk.cc.

18 {
19 if (!context || !swapchain_image || !swap_callback) {
20 return nullptr;
21 }
22
23 std::shared_ptr<Texture> msaa_tex;
24 if (enable_msaa) {
25 TextureDescriptor msaa_tex_desc;
26 msaa_tex_desc.storage_mode = StorageMode::kDeviceTransient;
27 msaa_tex_desc.type = TextureType::kTexture2DMultisample;
28 msaa_tex_desc.sample_count = SampleCount::kCount4;
29 msaa_tex_desc.format = swapchain_image->GetPixelFormat();
30 msaa_tex_desc.size = swapchain_image->GetSize();
31 msaa_tex_desc.usage = TextureUsage::kRenderTarget;
32
33 if (!swapchain_image->GetMSAATexture()) {
34 msaa_tex = context->GetResourceAllocator()->CreateTexture(msaa_tex_desc);
35 msaa_tex->SetLabel("ImpellerOnscreenColorMSAA");
36 if (!msaa_tex) {
37 VALIDATION_LOG << "Could not allocate MSAA color texture.";
38 return nullptr;
39 }
40 } else {
41 msaa_tex = swapchain_image->GetMSAATexture();
42 }
43 }
44
45 TextureDescriptor resolve_tex_desc;
46 resolve_tex_desc.type = TextureType::kTexture2D;
47 resolve_tex_desc.format = swapchain_image->GetPixelFormat();
48 resolve_tex_desc.size = swapchain_image->GetSize();
49 resolve_tex_desc.usage = TextureUsage::kRenderTarget;
50 resolve_tex_desc.sample_count = SampleCount::kCount1;
51 resolve_tex_desc.storage_mode = StorageMode::kDevicePrivate;
52
53 std::shared_ptr<Texture> resolve_tex =
54 std::make_shared<TextureVK>(context, //
55 swapchain_image //
56 );
57
58 if (!resolve_tex) {
59 VALIDATION_LOG << "Could not wrap resolve texture.";
60 return nullptr;
61 }
62 resolve_tex->SetLabel("ImpellerOnscreenResolve");
63
64 ColorAttachment color0;
65 color0.clear_color = Color::DarkSlateGray();
66 color0.load_action = LoadAction::kClear;
67 if (enable_msaa) {
68 color0.texture = msaa_tex;
69 color0.store_action = StoreAction::kMultisampleResolve;
70 color0.resolve_texture = resolve_tex;
71 } else {
72 color0.texture = resolve_tex;
73 color0.store_action = StoreAction::kStore;
74 }
75
76 RenderTarget render_target_desc;
77 render_target_desc.SetColorAttachment(color0, 0u);
78 render_target_desc.SetupDepthStencilAttachments(
79 /*context=*/*context, //
80 /*allocator=*/*context->GetResourceAllocator(), //
81 /*size=*/swapchain_image->GetSize(), //
82 /*msaa=*/enable_msaa, //
83 /*label=*/"Onscreen", //
84 /*stencil_attachment_config=*/
85 RenderTarget::kDefaultStencilAttachmentConfig, //
86 /*depth_stencil_texture=*/swapchain_image->GetDepthStencilTexture() //
87 );
88
89 // The constructor is private. So make_unique may not be used.
90 return std::unique_ptr<KHRSurfaceVK>(
91 new KHRSurfaceVK(render_target_desc, std::move(swap_callback)));
92 }

References impeller::ColorAttachment::clear_color, impeller::Color::DarkSlateGray(), impeller::TextureDescriptor::format, impeller::kClear, impeller::kCount1, impeller::kCount4, impeller::RenderTarget::kDefaultStencilAttachmentConfig, impeller::kDevicePrivate, impeller::kDeviceTransient, impeller::kMultisampleResolve, impeller::kRenderTarget, impeller::kStore, impeller::kTexture2D, impeller::kTexture2DMultisample, impeller::Attachment::load_action, impeller::Attachment::resolve_texture, impeller::TextureDescriptor::sample_count, impeller::RenderTarget::SetColorAttachment(), impeller::RenderTarget::SetupDepthStencilAttachments(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::Attachment::store_action, impeller::Attachment::texture, impeller::TextureDescriptor::type, impeller::TextureDescriptor::usage, and VALIDATION_LOG.

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

- impeller/renderer/backend/vulkan/swapchain/khr/khr_surface_vk.h
- impeller/renderer/backend/vulkan/swapchain/khr/khr_surface_vk.cc

impeller::StoreAction::kMultisampleResolve
@ kMultisampleResolve
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::Color::DarkSlateGray
static constexpr Color DarkSlateGray()
Definition: color.h:410
impeller::LoadAction::kClear
@ kClear
impeller::StorageMode::kDeviceTransient
@ kDeviceTransient
impeller::RenderTarget::kDefaultStencilAttachmentConfig
static constexpr AttachmentConfig kDefaultStencilAttachmentConfig
Definition: render_target.h:68
impeller::StorageMode::kDevicePrivate
@ kDevicePrivate
impeller::StoreAction::kStore
@ kStore
impeller::TextureType::kTexture2D
@ kTexture2D
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::SampleCount::kCount1
@ kCount1
impeller::SampleCount::kCount4
@ kCount4