15#include "third_party/skia/include/core/SkSurface.h"
16#include "third_party/skia/include/gpu/ganesh/SkSurfaceGanesh.h"
17#include "third_party/skia/include/gpu/ganesh/vk/GrVkDirectContext.h"
18#include "third_party/skia/include/gpu/vk/VulkanExtensions.h"
21#define VULKAN_SO_PATH "libvulkan.so"
29 PlatformView::Delegate& delegate,
30 const TaskRunners& task_runners,
31 const std::shared_ptr<ShellTestVsyncClock>& vsync_clock,
33 const std::shared_ptr<ShellTestExternalViewEmbedder>&
34 shell_test_external_view_embedder,
35 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch) {
36 return std::make_unique<ShellTestPlatformViewVulkan>(
37 delegate, task_runners, vsync_clock, create_vsync_waiter,
38 shell_test_external_view_embedder);
44 std::shared_ptr<ShellTestVsyncClock> vsync_clock,
46 std::shared_ptr<ShellTestExternalViewEmbedder>
47 shell_test_external_view_embedder)
49 create_vsync_waiter_(
std::move(create_vsync_waiter)),
50 vsync_clock_(
std::move(vsync_clock)),
52 shell_test_external_view_embedder_(
53 std::move(shell_test_external_view_embedder)) {}
57std::unique_ptr<VsyncWaiter> ShellTestPlatformViewVulkan::CreateVSyncWaiter() {
58 return create_vsync_waiter_();
62 vsync_clock_->SimulateVSync();
66std::unique_ptr<Surface> ShellTestPlatformViewVulkan::CreateRenderingSurface() {
67 return std::make_unique<OffScreenSurface>(proc_table_,
68 shell_test_external_view_embedder_);
72std::shared_ptr<ExternalViewEmbedder>
73ShellTestPlatformViewVulkan::CreateExternalViewEmbedder() {
74 return shell_test_external_view_embedder_;
79 return [](DefaultPointerDataDispatcher::Delegate& delegate) {
80 return std::make_unique<SmoothPointerDataDispatcher>(delegate);
88ShellTestPlatformViewVulkan::OffScreenSurface::OffScreenSurface(
90 std::shared_ptr<ShellTestExternalViewEmbedder>
91 shell_test_external_view_embedder)
93 shell_test_external_view_embedder_(
94 std::move(shell_test_external_view_embedder)) {
95 if (!vk_ || !vk_->HasAcquiredMandatoryProcAddresses()) {
96 FML_DLOG(ERROR) <<
"Proc table has not acquired mandatory proc addresses.";
101 std::vector<std::string> extensions = {
102 VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME,
105 application_ = std::make_unique<vulkan::VulkanApplication>(
106 *vk_,
"FlutterTest", std::move(extensions), VK_MAKE_VERSION(1, 0, 0),
107 VK_MAKE_VERSION(1, 1, 0),
true);
109 if (!application_->IsValid() || !vk_->AreInstanceProcsSetup()) {
112 FML_DLOG(ERROR) <<
"Instance proc addresses have not been set up.";
118 logical_device_ = application_->AcquireFirstCompatibleLogicalDevice();
120 if (logical_device_ ==
nullptr || !logical_device_->IsValid() ||
121 !vk_->AreDeviceProcsSetup()) {
124 FML_DLOG(ERROR) <<
"Device proc addresses have not been set up.";
129 application_->GetAPIVersion(), application_->GetInstance(),
130 logical_device_->GetPhysicalDeviceHandle(), logical_device_->GetHandle(),
134 if (!CreateSkiaGrContext()) {
135 FML_DLOG(ERROR) <<
"Could not create Skia context.";
142bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaGrContext() {
143 skgpu::VulkanBackendContext backend_context;
144 skgpu::VulkanExtensions no_extensions;
146 backend_context.fVkExtensions = &no_extensions;
147 VkPhysicalDeviceFeatures features;
152 if (!this->CreateSkiaBackendContext(&backend_context, &features)) {
153 FML_DLOG(ERROR) <<
"Could not create Skia backend context.";
160 sk_sp<GrDirectContext> context =
161 GrDirectContexts::MakeVulkan(backend_context, options);
163 if (context ==
nullptr) {
164 FML_DLOG(ERROR) <<
"Failed to create GrDirectContext";
175bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaBackendContext(
176 skgpu::VulkanBackendContext* context,
177 VkPhysicalDeviceFeatures* features) {
182 if (getProc ==
nullptr) {
183 FML_DLOG(ERROR) <<
"GetProcAddress is null";
187 if (!logical_device_->GetPhysicalDeviceFeatures(features)) {
188 FML_DLOG(ERROR) <<
"Failed to get Physical Device features";
192 context->fInstance = application_->GetInstance();
193 context->fPhysicalDevice = logical_device_->GetPhysicalDeviceHandle();
194 context->fDevice = logical_device_->GetHandle();
195 context->fQueue = logical_device_->GetQueueHandle();
196 context->fGraphicsQueueIndex = logical_device_->GetGraphicsQueueIndex();
197 context->fMaxAPIVersion = application_->GetAPIVersion();
198 context->fDeviceFeatures = features;
199 context->fGetProc = std::move(getProc);
200 context->fMemoryAllocator = memory_allocator_;
205ShellTestPlatformViewVulkan::OffScreenSurface::~OffScreenSurface() {}
207bool ShellTestPlatformViewVulkan::OffScreenSurface::IsValid() {
211std::unique_ptr<SurfaceFrame>
212ShellTestPlatformViewVulkan::OffScreenSurface::AcquireFrame(
214 auto image_info = SkImageInfo::Make(
size.width,
size.height,
215 SkColorType::kRGBA_8888_SkColorType,
216 SkAlphaType::kOpaque_SkAlphaType);
217 auto surface = SkSurfaces::RenderTarget(context_.get(), skgpu::Budgeted::kNo,
218 image_info, 0,
nullptr);
226 [](
const SurfaceFrame&) ->
bool {
return true; };
228 SurfaceFrame::FramebufferInfo framebuffer_info;
229 framebuffer_info.supports_readback =
true;
231 return std::make_unique<SurfaceFrame>(std::move(surface), framebuffer_info,
232 std::move(encode_callback),
233 std::move(submit_callback),
237GrDirectContext* ShellTestPlatformViewVulkan::OffScreenSurface::GetContext() {
238 return context_.get();
241DlMatrix ShellTestPlatformViewVulkan::OffScreenSurface::GetRootTransformation()
static sk_sp< VulkanMemoryAllocator > Make(uint32_t vulkan_api_version, VkInstance instance, VkPhysicalDevice physicalDevice, VkDevice device, const fml::RefPtr< vulkan::VulkanProcTable > &vk, bool mustUseCoherentHostVisibleMemory)
std::function< bool(SurfaceFrame &surface_frame, DlCanvas *canvas)> EncodeCallback
std::function< bool(SurfaceFrame &surface_frame)> SubmitCallback
#define FML_DLOG(severity)
#define FML_CHECK(condition)
std::function< std::unique_ptr< VsyncWaiter >()> CreateVsyncWaiter
impeller::Matrix DlMatrix
impeller::ISize32 DlISize
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
GrContextOptions MakeDefaultContextOptions(ContextType type, std::optional< GrBackendApi > api)
Initializes GrContextOptions with values suitable for Flutter. The options can be further tweaked bef...
std::function< std::unique_ptr< PointerDataDispatcher >(PointerDataDispatcher::Delegate &)> PointerDataDispatcherMaker
Signature for constructing PointerDataDispatcher.
@ kRender
The context is used to render to a texture or renderbuffer.
flutter::DlCanvas DlCanvas
skgpu::VulkanGetProc CreateSkiaGetProc(const fml::RefPtr< vulkan::VulkanProcTable > &vk)
static const size_t kGrCacheMaxByteSize