Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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"
16#include "third_party/skia/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 impeller::Flags impeller_flags)
34 : vk_(fml::MakeRefCounted<vulkan::VulkanProcTable>(
35 vulkan_dispatch_table.get_instance_proc_address)),
36 vulkan_dispatch_table_(vulkan_dispatch_table),
37 external_view_embedder_(std::move(external_view_embedder)) {
38 // Make sure all required members of the dispatch table are checked.
39 if (!vulkan_dispatch_table_.get_instance_proc_address ||
40 !vulkan_dispatch_table_.get_next_image ||
41 !vulkan_dispatch_table_.present_image) {
42 return;
43 }
44
45 std::vector<std::shared_ptr<fml::Mapping>> shader_mappings = {
46 std::make_shared<fml::NonOwnedMapping>(impeller_entity_shaders_vk_data,
47 impeller_entity_shaders_vk_length),
48 std::make_shared<fml::NonOwnedMapping>(impeller_modern_shaders_vk_data,
49 impeller_modern_shaders_vk_length),
50 std::make_shared<fml::NonOwnedMapping>(
51 impeller_framebuffer_blend_shaders_vk_data,
52 impeller_framebuffer_blend_shaders_vk_length),
53 };
55 settings.shader_libraries_data = shader_mappings;
56 settings.proc_address_callback =
57 vulkan_dispatch_table.get_instance_proc_address;
58 settings.flags = impeller_flags;
59
62 data.physical_device = physical_device;
63 data.device = device;
64 data.queue = queue;
65 data.queue_family_index = queue_family_index;
66 data.instance_extensions.reserve(instance_extension_count);
67 for (auto i = 0u; i < instance_extension_count; i++) {
68 data.instance_extensions.push_back(std::string{instance_extensions[i]});
69 }
70 data.device_extensions.reserve(device_extension_count);
71 for (auto i = 0u; i < device_extension_count; i++) {
72 data.device_extensions.push_back(std::string{device_extensions[i]});
73 }
74 settings.embedder_data = data;
75
76 context_ = impeller::ContextVK::Create(std::move(settings));
77 if (!context_) {
78 FML_LOG(ERROR) << "Failed to initialize Vulkan Context.";
79 return;
80 }
81
82 if (impeller_flags.use_sdfs) {
83 FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (VulkanSDF).";
84 } else {
85 FML_LOG(IMPORTANT) << "Using the Impeller rendering backend (Vulkan).";
86 }
87 valid_ = true;
88}
89
91
92std::shared_ptr<impeller::Context>
96
97// |GPUSurfaceVulkanDelegate|
101
102// |GPUSurfaceVulkanDelegate|
107
108// |GPUSurfaceVulkanDelegate|
110 VkFormat format) {
111 return vulkan_dispatch_table_.present_image(image, format);
112}
113
114// |EmbedderSurface|
115bool EmbedderSurfaceVulkanImpeller::IsValid() const {
116 return valid_;
117}
118
119// |EmbedderSurface|
120std::unique_ptr<Surface> EmbedderSurfaceVulkanImpeller::CreateGPUSurface() {
121 return std::make_unique<GPUSurfaceVulkanImpeller>(this, context_);
122}
123
124// |EmbedderSurface|
125sk_sp<GrDirectContext> EmbedderSurfaceVulkanImpeller::CreateResourceContext()
126 const {
127 return nullptr;
128}
129
130} // 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, impeller::Flags impeller_flags={})
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
std::vector< std::string > device_extensions
std::vector< std::string > instance_extensions
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
bool use_sdfs
Use SDFs for rendering.
Definition flags.h:13