Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
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)
 

Private Member Functions

std::shared_ptr< ContextGetContext () const override
 
WindowHandle GetWindowHandle () const override
 
std::unique_ptr< SurfaceAcquireSurfaceFrame (std::shared_ptr< Context > context) override
 

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) {
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 context_settings.fatal_missing_validations =
93 ;
94
95 auto context_vk = ContextVK::Create(std::move(context_settings));
96 if (!context_vk || !context_vk->IsValid()) {
97 VALIDATION_LOG << "Could not create Vulkan context in the playground.";
98 return;
99 }
100
101 VkSurfaceKHR vk_surface;
102 auto res = vk::Result{::glfwCreateWindowSurface(
103 context_vk->GetInstance(), // instance
104 window, // window
105 nullptr, // allocator
106 &vk_surface // surface
107 )};
108 if (res != vk::Result::eSuccess) {
109 VALIDATION_LOG << "Could not create surface for GLFW window: "
110 << vk::to_string(res);
111 return;
112 }
113
114 vk::UniqueSurfaceKHR surface{vk_surface, context_vk->GetInstance()};
115 auto context = context_vk->CreateSurfaceContext();
116 if (!context->SetWindowSurface(std::move(surface), size_)) {
117 VALIDATION_LOG << "Could not set up surface for context.";
118 return;
119 }
120
121 context_ = std::move(context);
122}
static std::shared_ptr< ContextVK > Create(Settings settings)
PlaygroundImpl(PlaygroundSwitches switches)
const PlaygroundSwitches switches_
GLFWwindow * window
Definition main.cc:45
VkSurfaceKHR surface
Definition main.cc:49
#define GLFW_FALSE
#define FML_CHECK(condition)
Definition logging.h:85
fml::UniqueFD GetCachesDirectory()
static std::vector< std::shared_ptr< fml::Mapping > > ShaderLibraryMappingsForPlayground()
TSize< int64_t > ISize
Definition size.h:138
int32_t height
int32_t width
#define VALIDATION_LOG
Definition validation.h:73
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)

◆ ~PlaygroundImplVK()

impeller::PlaygroundImplVK::~PlaygroundImplVK ( )
default

Member Function Documentation

◆ AcquireSurfaceFrame()

std::unique_ptr< Surface > impeller::PlaygroundImplVK::AcquireSurfaceFrame ( std::shared_ptr< Context context)
overrideprivatevirtual

Implements impeller::PlaygroundImpl.

Definition at line 137 of file playground_impl_vk.cc.

138 {
139 SurfaceContextVK* surface_context_vk =
140 reinterpret_cast<SurfaceContextVK*>(context_.get());
141
142 int width = 0;
143 int height = 0;
144 ::glfwGetFramebufferSize(reinterpret_cast<GLFWwindow*>(handle_.get()), &width,
145 &height);
146 size_ = ISize{width, height};
147 surface_context_vk->UpdateSurfaceSize(ISize{width, height});
148
149 return surface_context_vk->AcquireNextSurface();
150}

◆ GetContext()

std::shared_ptr< Context > impeller::PlaygroundImplVK::GetContext ( ) const
overrideprivatevirtual

Implements impeller::PlaygroundImpl.

Definition at line 127 of file playground_impl_vk.cc.

127 {
128 return context_;
129}

◆ GetWindowHandle()

PlaygroundImpl::WindowHandle impeller::PlaygroundImplVK::GetWindowHandle ( ) const
overrideprivatevirtual

Implements impeller::PlaygroundImpl.

Definition at line 132 of file playground_impl_vk.cc.

132 {
133 return handle_.get();
134}

◆ IsVulkanDriverPresent()

bool impeller::PlaygroundImplVK::IsVulkanDriverPresent ( )
static

Definition at line 219 of file playground_impl_vk.cc.

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

◆ SetCapabilities()

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

Implements impeller::PlaygroundImpl.

Definition at line 212 of file playground_impl_vk.cc.

213 {
214 return fml::Status(
216 "PlaygroundImplVK doesn't support setting the capabilities.");
217}

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