Skip to content

Commit

Permalink
Gate vk config initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero committed Nov 18, 2021
1 parent be42b6e commit 46ad11b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 48 deletions.
110 changes: 65 additions & 45 deletions shell/platform/embedder/tests/embedder_config_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#include "flutter/shell/platform/embedder/tests/embedder_test_context_gl.h"
#endif

//#ifdef SHELL_ENABLE_VULKAN
#ifdef SHELL_ENABLE_VULKAN
#include "flutter/shell/platform/embedder/tests/embedder_test_context_vulkan.h"
#include "flutter/vulkan/vulkan_device.h"
//#endif
#endif

#ifdef SHELL_ENABLE_METAL
#include "flutter/shell/platform/embedder/tests/embedder_test_context_metal.h"
Expand Down Expand Up @@ -74,53 +74,14 @@ EmbedderConfigBuilder::EmbedderConfigBuilder(
};
#endif

#ifdef SHELL_ENABLE_VULKAN
vulkan_renderer_config_.struct_size = sizeof(FlutterVulkanRendererConfig);
vulkan_renderer_config_.instance =
static_cast<EmbedderTestContextVulkan&>(context)
.application_->GetInstance();
vulkan_renderer_config_.physical_device =
static_cast<EmbedderTestContextVulkan&>(context)
.logical_device_->GetPhysicalDeviceHandle();
vulkan_renderer_config_.device =
static_cast<EmbedderTestContextVulkan&>(context)
.logical_device_->GetHandle();
vulkan_renderer_config_.queue_family_index =
static_cast<EmbedderTestContextVulkan&>(context)
.logical_device_->GetGraphicsQueueIndex();
vulkan_renderer_config_.queue =
static_cast<EmbedderTestContextVulkan&>(context)
.logical_device_->GetQueueHandle();
vulkan_renderer_config_.get_instance_proc_address_callback =
[](void* context, FlutterVulkanInstanceHandle instance,
const char* name) -> void* {
return reinterpret_cast<EmbedderTestContextVulkan*>(context)
->vk_->GetInstanceProcAddr(reinterpret_cast<VkInstance>(instance),
name);
};
vulkan_renderer_config_.get_next_image_callback =
[](void* context,
const FlutterFrameInfo* frame_info) -> FlutterVulkanImage {
VkImage image =
reinterpret_cast<EmbedderTestContextVulkan*>(context)->GetNextImage(
{static_cast<int>(frame_info->size.width),
static_cast<int>(frame_info->size.height)});
return {
.struct_size = sizeof(FlutterVulkanImage),
.image = image,
};
};
vulkan_renderer_config_.present_image_callback =
[](void* context, const FlutterVulkanImage* image) -> bool {
return reinterpret_cast<EmbedderTestContextVulkan*>(context)->PresentImage(
reinterpret_cast<VkImage>(image->image));
};
#endif

#ifdef SHELL_ENABLE_METAL
InitializeMetalRendererConfig();
#endif

#ifdef SHELL_ENABLE_VULKAN
InitializeVulkanRendererConfig();
#endif

software_renderer_config_.struct_size = sizeof(FlutterSoftwareRendererConfig);
software_renderer_config_.surface_present_callback =
[](void* context, const void* allocation, size_t row_bytes,
Expand Down Expand Up @@ -218,6 +179,14 @@ void EmbedderConfigBuilder::SetMetalRendererConfig(SkISize surface_size) {
#endif
}

void EmbedderConfigBuilder::SetVulkanRendererConfig(SkISize surface_size) {
#ifdef SHELL_ENABLE_VULKAN
renderer_config_.type = FlutterRendererType::kVulkan;
renderer_config_.vulkan = vulkan_renderer_config_;
context_.SetupSurface(surface_size);
#endif
}

void EmbedderConfigBuilder::SetAssetsPath() {
project_args_.assets_path = context_.GetAssetsPath().c_str();
}
Expand Down Expand Up @@ -476,5 +445,56 @@ void EmbedderConfigBuilder::InitializeMetalRendererConfig() {

#endif // SHELL_ENABLE_METAL

#ifdef SHELL_ENABLE_VULKAN

void EmbedderConfigBuilder::InitializeVulkanRendererConfig() {
if (context_.GetContextType() != EmbedderTestContextType::kVulkanContext) {
return;
}

vulkan_renderer_config_.struct_size = sizeof(FlutterVulkanRendererConfig);
vulkan_renderer_config_.instance =
static_cast<EmbedderTestContextVulkan&>(context_)
.application_->GetInstance();
vulkan_renderer_config_.physical_device =
static_cast<EmbedderTestContextVulkan&>(context_)
.logical_device_->GetPhysicalDeviceHandle();
vulkan_renderer_config_.device =
static_cast<EmbedderTestContextVulkan&>(context_)
.logical_device_->GetHandle();
vulkan_renderer_config_.queue_family_index =
static_cast<EmbedderTestContextVulkan&>(context_)
.logical_device_->GetGraphicsQueueIndex();
vulkan_renderer_config_.queue =
static_cast<EmbedderTestContextVulkan&>(context_)
.logical_device_->GetQueueHandle();
vulkan_renderer_config_.get_instance_proc_address_callback =
[](void* context, FlutterVulkanInstanceHandle instance,
const char* name) -> void* {
return reinterpret_cast<EmbedderTestContextVulkan*>(context)
->vk_->GetInstanceProcAddr(reinterpret_cast<VkInstance>(instance),
name);
};
vulkan_renderer_config_.get_next_image_callback =
[](void* context,
const FlutterFrameInfo* frame_info) -> FlutterVulkanImage {
VkImage image =
reinterpret_cast<EmbedderTestContextVulkan*>(context)->GetNextImage(
{static_cast<int>(frame_info->size.width),
static_cast<int>(frame_info->size.height)});
return {
.struct_size = sizeof(FlutterVulkanImage),
.image = image,
};
};
vulkan_renderer_config_.present_image_callback =
[](void* context, const FlutterVulkanImage* image) -> bool {
return reinterpret_cast<EmbedderTestContextVulkan*>(context)->PresentImage(
reinterpret_cast<VkImage>(image->image));
};
}

#endif

} // namespace testing
} // namespace flutter
5 changes: 3 additions & 2 deletions shell/platform/embedder/tests/embedder_config_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class EmbedderConfigBuilder {

void SetOpenGLRendererConfig(SkISize surface_size);

void SetVulkanRendererConfig(SkISize surface_size);

void SetMetalRendererConfig(SkISize surface_size);

void SetVulkanRendererConfig(SkISize surface_size);

// Used to explicitly set an `open_gl.fbo_callback`. Using this method will
// cause your test to fail since the ctor for this class sets
// `open_gl.fbo_callback_with_frame_info`. This method exists as a utility to
Expand Down Expand Up @@ -119,6 +119,7 @@ class EmbedderConfigBuilder {
FlutterOpenGLRendererConfig opengl_renderer_config_ = {};
#endif
#ifdef SHELL_ENABLE_VULKAN
void InitializeVulkanRendererConfig();
FlutterVulkanRendererConfig vulkan_renderer_config_ = {};
#endif
#ifdef SHELL_ENABLE_METAL
Expand Down
1 change: 0 additions & 1 deletion vulkan/vulkan_proc_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ VulkanProcTable::VulkanProcTable() : VulkanProcTable("libvulkan.so"){};

VulkanProcTable::VulkanProcTable(const char* so_path)
: handle_(nullptr), acquired_mandatory_proc_addresses_(false) {
FML_DLOG(WARNING) << "Cowabunga";
acquired_mandatory_proc_addresses_ = OpenLibraryHandle(so_path) &&
SetupGetInstanceProcAddress() &&
SetupLoaderProcAddresses();
Expand Down

0 comments on commit 46ad11b

Please sign in to comment.