Flutter Engine
 
Loading...
Searching...
No Matches
android_context_vk_impeller.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
8#include "flutter/fml/paths.h"
9#include "flutter/impeller/entity/vk/entity_shaders_vk.h"
10#include "flutter/impeller/entity/vk/framebuffer_blend_shaders_vk.h"
11#include "flutter/impeller/entity/vk/modern_shaders_vk.h"
15
16namespace flutter {
17
18static std::shared_ptr<impeller::Context> CreateImpellerContext(
19 const fml::RefPtr<fml::NativeLibrary>& vulkan_dylib,
20 const AndroidContext::ContextSettings& p_settings) {
21 if (!vulkan_dylib) {
22 VALIDATION_LOG << "Could not open the Vulkan dylib.";
23 return nullptr;
24 }
25
26 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
27 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
28 impeller_entity_shaders_vk_length),
29 std::make_shared<fml::NonOwnedMapping>(
30 impeller_framebuffer_blend_shaders_vk_data,
31 impeller_framebuffer_blend_shaders_vk_length),
32 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_vk_data,
33 impeller_modern_shaders_vk_length),
34 };
35
36 auto instance_proc_addr =
37 vulkan_dylib->ResolveFunction<PFN_vkGetInstanceProcAddr>(
38 "vkGetInstanceProcAddr");
39
40 if (!instance_proc_addr.has_value()) {
41 VALIDATION_LOG << "Could not setup Vulkan proc table.";
42 return nullptr;
43 }
44
46 settings.proc_address_callback = instance_proc_addr.value();
47 settings.shader_libraries_data = std::move(shader_mappings);
49 settings.enable_validation = p_settings.enable_validation;
50 settings.enable_gpu_tracing = p_settings.enable_gpu_tracing;
52 settings.flags = p_settings.impeller_flags;
53
54 auto context = impeller::ContextVK::Create(std::move(settings));
55
56 if (!p_settings.quiet) {
57 if (context && impeller::CapabilitiesVK::Cast(*context->GetCapabilities())
59 FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Vulkan with "
60 "Validation Layers).";
61 } else {
62 FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Vulkan).";
63 }
64 }
65 if (context && context->GetDriverInfo()->IsKnownBadDriver()) {
66 FML_LOG(INFO)
67 << "Known bad Vulkan driver encountered, falling back to OpenGLES.";
68 return nullptr;
69 }
70
71 return context;
72}
73
75 const AndroidContext::ContextSettings& settings)
77 vulkan_dylib_(fml::NativeLibrary::Create("libvulkan.so")) {
78 auto impeller_context = CreateImpellerContext(vulkan_dylib_, settings);
79 is_valid_ = !!impeller_context;
80 SetImpellerContext(impeller_context);
81}
82
84
86 return is_valid_;
87}
88
92
93} // namespace flutter
static std::shared_ptr< impeller::ContextMTL > CreateImpellerContext()
Holds state that is shared across Android surfaces.
void SetImpellerContext(const std::shared_ptr< impeller::Context > &impeller_context)
AndroidContextVKImpeller(const AndroidContext::ContextSettings &settings)
AndroidRenderingAPI RenderingApi() const override
static CapabilitiesVK & Cast(Capabilities &base)
static std::shared_ptr< ContextVK > Create(Settings settings)
#define FML_LOG(severity)
Definition logging.h:101
fml::UniqueFD GetCachesDirectory()
std::vector< std::shared_ptr< fml::Mapping > > shader_libraries_data
Definition context_vk.h:81
PFN_vkGetInstanceProcAddr proc_address_callback
Definition context_vk.h:80
#define VALIDATION_LOG
Definition validation.h:91