Skip to content

Commit f9a169e

Browse files
authored
Sever the //flutter/vulkan dependency in Flutter in the Android embedder. (#50472)
The previous code was setting up a proc table, then getting the address of the proc that was used to the setup that table, then setting up another proc table. Directly setup the final proc table and don't depend on //impeller/vulkan. Part of #143127 Similar to flutter/engine#50454
1 parent 794552e commit f9a169e

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

shell/platform/android/android_context_vulkan_impeller.cc

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717
namespace flutter {
1818

1919
static std::shared_ptr<impeller::Context> CreateImpellerContext(
20-
const fml::RefPtr<vulkan::VulkanProcTable>& proc_table,
20+
const fml::RefPtr<fml::NativeLibrary>& vulkan_dylib,
2121
bool enable_vulkan_validation,
2222
bool enable_gpu_tracing) {
23+
if (!vulkan_dylib) {
24+
VALIDATION_LOG << "Could not open the Vulkan dylib.";
25+
return nullptr;
26+
}
27+
2328
std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
2429
std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
2530
impeller_entity_shaders_vk_length),
@@ -34,11 +39,17 @@ static std::shared_ptr<impeller::Context> CreateImpellerContext(
3439
impeller_modern_shaders_vk_length),
3540
};
3641

37-
PFN_vkGetInstanceProcAddr instance_proc_addr =
38-
proc_table->NativeGetInstanceProcAddr();
42+
auto instance_proc_addr =
43+
vulkan_dylib->ResolveFunction<PFN_vkGetInstanceProcAddr>(
44+
"vkGetInstanceProcAddr");
45+
46+
if (!instance_proc_addr.has_value()) {
47+
VALIDATION_LOG << "Could not setup Vulkan proc table.";
48+
return nullptr;
49+
}
3950

4051
impeller::ContextVK::Settings settings;
41-
settings.proc_address_callback = instance_proc_addr;
52+
settings.proc_address_callback = instance_proc_addr.value();
4253
settings.shader_libraries_data = std::move(shader_mappings);
4354
settings.cache_directory = fml::paths::GetCachesDirectory();
4455
settings.enable_validation = enable_vulkan_validation;
@@ -61,12 +72,11 @@ AndroidContextVulkanImpeller::AndroidContextVulkanImpeller(
6172
bool enable_validation,
6273
bool enable_gpu_tracing)
6374
: AndroidContext(AndroidRenderingAPI::kVulkan),
64-
proc_table_(fml::MakeRefCounted<vulkan::VulkanProcTable>()) {
65-
auto impeller_context =
66-
CreateImpellerContext(proc_table_, enable_validation, enable_gpu_tracing);
75+
vulkan_dylib_(fml::NativeLibrary::Create("libvulkan.so")) {
76+
auto impeller_context = CreateImpellerContext(
77+
vulkan_dylib_, enable_validation, enable_gpu_tracing);
6778
SetImpellerContext(impeller_context);
68-
is_valid_ =
69-
proc_table_->HasAcquiredMandatoryProcAddresses() && impeller_context;
79+
is_valid_ = !!impeller_context;
7080
}
7181

7282
AndroidContextVulkanImpeller::~AndroidContextVulkanImpeller() = default;

shell/platform/android/android_context_vulkan_impeller.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include "flutter/fml/concurrent_message_loop.h"
99
#include "flutter/fml/macros.h"
10+
#include "flutter/fml/native_library.h"
1011
#include "flutter/shell/platform/android/context/android_context.h"
11-
#include "flutter/vulkan/procs/vulkan_proc_table.h"
1212

1313
namespace flutter {
1414

@@ -22,7 +22,7 @@ class AndroidContextVulkanImpeller : public AndroidContext {
2222
bool IsValid() const override;
2323

2424
private:
25-
fml::RefPtr<vulkan::VulkanProcTable> proc_table_;
25+
fml::RefPtr<fml::NativeLibrary> vulkan_dylib_;
2626
bool is_valid_ = false;
2727

2828
FML_DISALLOW_COPY_AND_ASSIGN(AndroidContextVulkanImpeller);

0 commit comments

Comments
 (0)