Flutter Engine
 
Loading...
Searching...
No Matches
embedder_surface_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
6
7#include <utility>
8
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#include "include/gpu/ganesh/GrDirectContext.h"
17
18namespace flutter {
19
21 uint32_t version,
22 VkInstance instance,
23 size_t instance_extension_count,
24 const char** instance_extensions,
25 size_t device_extension_count,
26 const char** device_extensions,
27 VkPhysicalDevice physical_device,
28 VkDevice device,
29 uint32_t queue_family_index,
30 VkQueue queue,
31 const VulkanDispatchTable& vulkan_dispatch_table,
32 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder)
33 : vk_(fml::MakeRefCounted<vulkan::VulkanProcTable>(
34 vulkan_dispatch_table.get_instance_proc_address)),
35 vulkan_dispatch_table_(vulkan_dispatch_table),
36 external_view_embedder_(std::move(external_view_embedder)) {
37 // Make sure all required members of the dispatch table are checked.
38 if (!vulkan_dispatch_table_.get_instance_proc_address ||
39 !vulkan_dispatch_table_.get_next_image ||
40 !vulkan_dispatch_table_.present_image) {
41 return;
42 }
43
44 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
45 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
46 impeller_entity_shaders_vk_length),
47 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_vk_data,
48 impeller_modern_shaders_vk_length),
49 std::make_shared<fml::NonOwnedMapping>(
50 impeller_framebuffer_blend_shaders_vk_data,
51 impeller_framebuffer_blend_shaders_vk_length),
52 };
54 settings.shader_libraries_data = shader_mappings;
55 settings.proc_address_callback =
56 vulkan_dispatch_table.get_instance_proc_address;
57
60 data.physical_device = physical_device;
61 data.device = device;
62 data.queue = queue;
63 data.queue_family_index = queue_family_index;
64 data.instance_extensions.reserve(instance_extension_count);
65 for (auto i = 0u; i < instance_extension_count; i++) {
66 data.instance_extensions.push_back(std::string{instance_extensions[i]});
67 }
68 data.device_extensions.reserve(device_extension_count);
69 for (auto i = 0u; i < device_extension_count; i++) {
70 data.device_extensions.push_back(std::string{device_extensions[i]});
71 }
72 settings.embedder_data = data;
73
74 context_ = impeller::ContextVK::Create(std::move(settings));
75 if (!context_) {
76 FML_LOG(ERROR) << "Failed to initialize Vulkan Context.";
77 return;
78 }
79
80 FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Vulkan).";
81
82 valid_ = true;
83}
84
86
87std::shared_ptr<impeller::Context>
91
92// |GPUSurfaceVulkanDelegate|
96
97// |GPUSurfaceVulkanDelegate|
102
103// |GPUSurfaceVulkanDelegate|
105 VkFormat format) {
106 return vulkan_dispatch_table_.present_image(image, format);
107}
108
109// |EmbedderSurface|
110bool EmbedderSurfaceVulkanImpeller::IsValid() const {
111 return valid_;
112}
113
114// |EmbedderSurface|
115std::unique_ptr<Surface> EmbedderSurfaceVulkanImpeller::CreateGPUSurface() {
116 return std::make_unique<GPUSurfaceVulkanImpeller>(this, context_);
117}
118
119// |EmbedderSurface|
120sk_sp<GrDirectContext> EmbedderSurfaceVulkanImpeller::CreateResourceContext()
121 const {
122 return nullptr;
123}
124
125} // namespace flutter
std::shared_ptr< impeller::Context > CreateImpellerContext() const override
EmbedderSurfaceVulkanImpeller(uint32_t version, VkInstance instance, size_t instance_extension_count, const char **instance_extensions, size_t device_extension_count, const char **device_extensions, VkPhysicalDevice physical_device, VkDevice device, uint32_t queue_family_index, VkQueue queue, const VulkanDispatchTable &vulkan_dispatch_table, std::shared_ptr< EmbedderExternalViewEmbedder > external_view_embedder)
FlutterVulkanImage AcquireImage(const DlISize &size) override
Called by the engine to fetch a VkImage for writing the next frame.
bool PresentImage(VkImage image, VkFormat format) override
Called by the engine once a frame has been rendered to the image and it's ready to be bound for furth...
const vulkan::VulkanProcTable & vk() override
Obtain a reference to the Vulkan implementation's proc table.
static std::shared_ptr< ContextVK > Create(Settings settings)
FlutterVulkanImage * image
VkPhysicalDevice physical_device
Definition main.cc:67
VkDevice device
Definition main.cc:69
VkInstance instance
Definition main.cc:64
VkQueue queue
Definition main.cc:71
uint32_t queue_family_index
Definition main.cc:70
uint32_t uint32_t * format
#define FML_LOG(severity)
Definition logging.h:101
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switch_defs.h:36
Definition ref_ptr.h:261
std::function< bool(VkImage image, VkFormat format)> present_image
std::function< FlutterVulkanImage(const DlISize &frame_size)> get_next_image
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
std::optional< EmbedderData > embedder_data
Definition context_vk.h:90