| Flutter Impeller |

Public Member Functions | List of all members
impeller::PlaygroundImplVK Class Referencefinal

`#include <playground_impl_vk.h>`

Inheritance diagram for impeller::PlaygroundImplVK:

## Public Member Functions
| PlaygroundImplVK (PlaygroundSwitches switches)
| ~PlaygroundImplVK ()
fml::Status | SetCapabilities (const std::shared_ptr< Capabilities > &capabilities) override
Public Member Functions inherited from impeller::PlaygroundImpl
virtual | ~PlaygroundImpl ()
Vector2 | GetContentScale () const

## Additional Inherited Members
Public Types inherited from impeller::PlaygroundImpl
using | WindowHandle = void *
Static Public Member Functions inherited from impeller::PlaygroundImpl
static std::unique_ptr< PlaygroundImpl > | Create (PlaygroundBackend backend, PlaygroundSwitches switches)
Protected Member Functions inherited from impeller::PlaygroundImpl
| PlaygroundImpl (PlaygroundSwitches switches)
Protected Attributes inherited from impeller::PlaygroundImpl
const PlaygroundSwitches | switches_

## Detailed Description

Definition at line 14 of file playground_impl_vk.h.

## Constructor & Destructor Documentation

## ◆ PlaygroundImplVK()

impeller::PlaygroundImplVK::PlaygroundImplVK | ( | PlaygroundSwitches | switches | ) |
| explicit

Definition at line 61 of file playground_impl_vk.cc.

62 : PlaygroundImpl(switches), handle_(nullptr, &DestroyWindowHandle) {
63 if (!::glfwVulkanSupported()) {
64 #ifdef TARGET_OS_MAC
65 VALIDATION_LOG << "Attempted to initialize a Vulkan playground on macOS "
66 "where Vulkan cannot be found. It can be installed via "
67 "MoltenVK and make sure to install it globally so "
68 "dlopen can find it.";
69 #else
70 VALIDATION_LOG << "Attempted to initialize a Vulkan playground on a system "
71 "that does not support Vulkan.";
72 #endif
73 return;
74 }
75
76 InitGlobalVulkanInstance();
77
78 ::glfwDefaultWindowHints();
79 ::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
80 ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
81
82 auto window = ::glfwCreateWindow(1, 1, "Test", nullptr, nullptr);
83 if (!window) {
84 VALIDATION_LOG << "Unable to create glfw window";
85 return;
86 }
87
88 handle_.reset(window);
89
90 ContextVK::Settings context_settings;
91 context_settings.proc_address_callback =
92 reinterpret_cast<PFN_vkGetInstanceProcAddr>(
93 &::glfwGetInstanceProcAddress);
94 context_settings.shader_libraries_data = ShaderLibraryMappingsForPlayground();
95 context_settings.cache_directory = fml::paths::GetCachesDirectory();
96 context_settings.enable_validation = switches_.enable_vulkan_validation;
97
98 auto context_vk = ContextVK::Create(std::move(context_settings));
99 if (!context_vk || !context_vk->IsValid()) {
100 VALIDATION_LOG << "Could not create Vulkan context in the playground.";
101 return;
102 }
103
104 // Without this, the playground will timeout waiting for the presentation.
105 // It's better to have some Vulkan validation tests running on CI to catch
106 // regressions, but for now this is a workaround.
107 //
108 // TODO(matanlurey): https://github.com/flutter/flutter/issues/134852.
109 //
110 // (Note, if you're using MoltenVK, or Linux, you can comment out this line).
111 context_vk->SetSyncPresentation(true);
112
113 VkSurfaceKHR vk_surface;
114 auto res = vk::Result{::glfwCreateWindowSurface(
115 context_vk->GetInstance(), // instance
116 window, // window
117 nullptr, // allocator
118 &vk_surface // surface
119 )};
120 if (res != vk::Result::eSuccess) {
121 VALIDATION_LOG << "Could not create surface for GLFW window: "
122 << vk::to_string(res);
123 return;
124 }
125
126 vk::UniqueSurfaceKHR surface{vk_surface, context_vk->GetInstance()};
127 auto context = context_vk->CreateSurfaceContext();
128 if (!context->SetWindowSurface(std::move(surface))) {
129 VALIDATION_LOG << "Could not set up surface for context.";
130 return;
131 }
132
133 context_ = std::move(context);
134 }

References impeller::ContextVK::Settings::cache_directory, impeller::ContextVK::Create(), impeller::ContextVK::Settings::enable_validation, impeller::PlaygroundSwitches::enable_vulkan_validation, impeller::ContextVK::Settings::proc_address_callback, impeller::ContextVK::Settings::shader_libraries_data, impeller::ShaderLibraryMappingsForPlayground(), impeller::PlaygroundImpl::switches_, and VALIDATION_LOG.

## ◆ ~PlaygroundImplVK()

impeller::PlaygroundImplVK::~PlaygroundImplVK | ( |  | ) |
| default

## Member Function Documentation

## ◆ SetCapabilities()

fml::Status impeller::PlaygroundImplVK::SetCapabilities | ( | const std::shared_ptr< Capabilities > & | capabilities | ) |
| override virtual

Implements impeller::PlaygroundImpl.

Definition at line 185 of file playground_impl_vk.cc.

186 {
187 return fml::Status(
188 fml::StatusCode::kUnimplemented,
189 "PlaygroundImplVK doesn't support setting the capabilities.");
190 }

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

- impeller/playground/backend/vulkan/playground_impl_vk.h
- impeller/playground/backend/vulkan/playground_impl_vk.cc

impeller::ShaderLibraryMappingsForPlayground
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappingsForPlayground()
Definition: playground_impl_gles.cc:91
impeller::ContextVK::Create
static std::shared_ptr< ContextVK > Create(Settings settings)
Definition: context_vk.cc:95
impeller::PlaygroundImpl::switches_
const PlaygroundSwitches switches_
Definition: playground_impl.h:40
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
impeller::PlaygroundSwitches::enable_vulkan_validation
bool enable_vulkan_validation
Definition: switches.h:22
impeller::PlaygroundImpl::PlaygroundImpl
PlaygroundImpl(PlaygroundSwitches switches)
Definition: playground_impl.cc:48