Flutter Impeller
impeller::PlaygroundImplVK Class Referencefinal

#include <playground_impl_vk.h>

Inheritance diagram for impeller::PlaygroundImplVK:
impeller::PlaygroundImpl

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
 

Static Public Member Functions

static bool IsVulkanDriverPresent ()
 
- Static Public Member Functions inherited from impeller::PlaygroundImpl
static std::unique_ptr< PlaygroundImplCreate (PlaygroundBackend backend, PlaygroundSwitches switches)
 

Additional Inherited Members

- Public Types inherited from impeller::PlaygroundImpl
using WindowHandle = void *
 
- Protected Member Functions inherited from impeller::PlaygroundImpl
 PlaygroundImpl (PlaygroundSwitches switches)
 
- Protected Attributes inherited from impeller::PlaygroundImpl
const PlaygroundSwitches switches_
 

Detailed Description

Definition at line 13 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  FML_CHECK(IsVulkanDriverPresent());
64 
65  InitGlobalVulkanInstance();
66 
67  ::glfwDefaultWindowHints();
68  ::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
69  ::glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
70 
71  auto window = ::glfwCreateWindow(1, 1, "Test", nullptr, nullptr);
72  if (!window) {
73  VALIDATION_LOG << "Unable to create glfw window";
74  return;
75  }
76 
77  int width = 0;
78  int height = 0;
79  ::glfwGetWindowSize(window, &width, &height);
80  size_ = ISize{width, height};
81 
82  handle_.reset(window);
83 
84  ContextVK::Settings context_settings;
85  context_settings.proc_address_callback =
86  reinterpret_cast<PFN_vkGetInstanceProcAddr>(
87  &::glfwGetInstanceProcAddress);
88  context_settings.shader_libraries_data = ShaderLibraryMappingsForPlayground();
89  context_settings.cache_directory = fml::paths::GetCachesDirectory();
90  context_settings.enable_validation = switches_.enable_vulkan_validation;
91 
92  auto context_vk = ContextVK::Create(std::move(context_settings));
93  if (!context_vk || !context_vk->IsValid()) {
94  VALIDATION_LOG << "Could not create Vulkan context in the playground.";
95  return;
96  }
97 
98  VkSurfaceKHR vk_surface;
99  auto res = vk::Result{::glfwCreateWindowSurface(
100  context_vk->GetInstance(), // instance
101  window, // window
102  nullptr, // allocator
103  &vk_surface // surface
104  )};
105  if (res != vk::Result::eSuccess) {
106  VALIDATION_LOG << "Could not create surface for GLFW window: "
107  << vk::to_string(res);
108  return;
109  }
110 
111  vk::UniqueSurfaceKHR surface{vk_surface, context_vk->GetInstance()};
112  auto context = context_vk->CreateSurfaceContext();
113  if (!context->SetWindowSurface(std::move(surface), size_)) {
114  VALIDATION_LOG << "Could not set up surface for context.";
115  return;
116  }
117 
118  context_ = std::move(context);
119 }

References impeller::ContextVK::Settings::cache_directory, impeller::ContextVK::Create(), impeller::ContextVK::Settings::enable_validation, impeller::PlaygroundSwitches::enable_vulkan_validation, IsVulkanDriverPresent(), 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

◆ IsVulkanDriverPresent()

bool impeller::PlaygroundImplVK::IsVulkanDriverPresent ( )
static

Definition at line 216 of file playground_impl_vk.cc.

216  {
217  if (::glfwVulkanSupported()) {
218  return true;
219  }
220 #ifdef TARGET_OS_MAC
221  FML_LOG(ERROR) << "Attempting to initialize a Vulkan playground on macOS "
222  "where Vulkan cannot be found. It can be installed via "
223  "MoltenVK and make sure to install it globally so "
224  "dlopen can find it.";
225 #else // TARGET_OS_MAC
226  FML_LOG(ERROR) << "Attempting to initialize a Vulkan playground on a system "
227  "that does not support Vulkan.";
228 #endif // TARGET_OS_MAC
229  return false;
230 }

Referenced by impeller::PlaygroundImpl::Create(), PlaygroundImplVK(), and impeller::Playground::SupportsBackend().

◆ SetCapabilities()

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

Implements impeller::PlaygroundImpl.

Definition at line 209 of file playground_impl_vk.cc.

210  {
211  return fml::Status(
212  fml::StatusCode::kUnimplemented,
213  "PlaygroundImplVK doesn't support setting the capabilities.");
214 }

The documentation for this class was generated from the following files:
impeller::PlaygroundImplVK::IsVulkanDriverPresent
static bool IsVulkanDriverPresent()
Definition: playground_impl_vk.cc:216
impeller::ShaderLibraryMappingsForPlayground
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappingsForPlayground()
Definition: playground_impl_gles.cc:106
impeller::ContextVK::Create
static std::shared_ptr< ContextVK > Create(Settings settings)
Definition: context_vk.cc:100
impeller::ISize
TSize< int64_t > ISize
Definition: size.h:138
impeller::PlaygroundImpl::switches_
const PlaygroundSwitches switches_
Definition: playground_impl.h:40
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::PlaygroundSwitches::enable_vulkan_validation
bool enable_vulkan_validation
Definition: switches.h:22
impeller::PlaygroundImpl::PlaygroundImpl
PlaygroundImpl(PlaygroundSwitches switches)
Definition: playground_impl.cc:55