Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
android_context_vulkan_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
5#include "flutter/shell/platform/android/android_context_vulkan_impeller.h"
6
7#include "flutter/fml/paths.h"
8#include "flutter/impeller/entity/vk/entity_shaders_vk.h"
9#include "flutter/impeller/entity/vk/framebuffer_blend_shaders_vk.h"
10#include "flutter/impeller/entity/vk/modern_shaders_vk.h"
11#include "flutter/impeller/renderer/backend/vulkan/context_vk.h"
12
13#if IMPELLER_ENABLE_3D
14#include "flutter/impeller/scene/shaders/vk/scene_shaders_vk.h" // nogncheck
15#endif // IMPELLER_ENABLE_3D
16
17namespace flutter {
18
19static std::shared_ptr<impeller::Context> CreateImpellerContext(
20 const fml::RefPtr<fml::NativeLibrary>& vulkan_dylib,
21 bool enable_vulkan_validation,
22 bool enable_gpu_tracing,
23 bool quiet) {
24 if (!vulkan_dylib) {
25 VALIDATION_LOG << "Could not open the Vulkan dylib.";
26 return nullptr;
27 }
28
29 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
30 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
31 impeller_entity_shaders_vk_length),
32 std::make_shared<fml::NonOwnedMapping>(
33 impeller_framebuffer_blend_shaders_vk_data,
34 impeller_framebuffer_blend_shaders_vk_length),
35#if IMPELLER_ENABLE_3D
36 std::make_shared<fml::NonOwnedMapping>(impeller_scene_shaders_vk_data,
37 impeller_scene_shaders_vk_length),
38#endif
39 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_vk_data,
40 impeller_modern_shaders_vk_length),
41 };
42
43 auto instance_proc_addr =
44 vulkan_dylib->ResolveFunction<PFN_vkGetInstanceProcAddr>(
45 "vkGetInstanceProcAddr");
46
47 if (!instance_proc_addr.has_value()) {
48 VALIDATION_LOG << "Could not setup Vulkan proc table.";
49 return nullptr;
50 }
51
53 settings.proc_address_callback = instance_proc_addr.value();
54 settings.shader_libraries_data = std::move(shader_mappings);
55 settings.cache_directory = fml::paths::GetCachesDirectory();
56 settings.enable_validation = enable_vulkan_validation;
57 settings.enable_gpu_tracing = enable_gpu_tracing;
58
59 auto context = impeller::ContextVK::Create(std::move(settings));
60
61 if (!quiet) {
62 if (context && impeller::CapabilitiesVK::Cast(*context->GetCapabilities())
64 FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Vulkan with "
65 "Validation Layers).";
66 } else {
67 FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Vulkan).";
68 }
69 }
70
71 return context;
72}
73
75 bool enable_validation,
76 bool enable_gpu_tracing,
77 bool quiet)
79 vulkan_dylib_(fml::NativeLibrary::Create("libvulkan.so")) {
80 auto impeller_context = CreateImpellerContext(
81 vulkan_dylib_, enable_validation, enable_gpu_tracing, quiet);
82 SetImpellerContext(impeller_context);
83 is_valid_ = !!impeller_context;
84}
85
87
89 return is_valid_;
90}
91
92} // namespace flutter
static sk_sp< Effect > Create()
AndroidContextVulkanImpeller(bool enable_validation, bool enable_gpu_tracing, bool quiet=false)
Holds state that is shared across Android surfaces.
void SetImpellerContext(const std::shared_ptr< impeller::Context > &context)
static CapabilitiesVK & Cast(Capabilities &base)
static std::shared_ptr< ContextVK > Create(Settings settings)
#define FML_LOG(severity)
Definition logging.h:82
AndroidRenderingAPI
Definition settings.h:26
static std::shared_ptr< impeller::Context > CreateImpellerContext(const std::shared_ptr< impeller::ReactorGLES::Worker > &worker, bool enable_gpu_tracing)
fml::UniqueFD GetCachesDirectory()
#define VALIDATION_LOG
Definition validation.h:73
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)