diff --git a/shell/common/animator_unittests.cc b/shell/common/animator_unittests.cc index a4467371aba3b..1f8bb22db642c 100644 --- a/shell/common/animator_unittests.cc +++ b/shell/common/animator_unittests.cc @@ -88,8 +88,8 @@ TEST_F(ShellTest, VSyncTargetTime) { flutter::PlatformData(), task_runners, settings, [vsync_clock, &create_vsync_waiter](Shell& shell) { return ShellTestPlatformView::Create( - shell, shell.GetTaskRunners(), vsync_clock, create_vsync_waiter, - ShellTestPlatformView::BackendType::kDefaultBackend, nullptr, + ShellTestPlatformView::DefaultBackendType(), shell, + shell.GetTaskRunners(), vsync_clock, create_vsync_waiter, nullptr, shell.GetIsGpuDisabledSyncSwitch()); }, [](Shell& shell) { return std::make_unique(shell); }); diff --git a/shell/common/shell_test_platform_view.cc b/shell/common/shell_test_platform_view.cc index 248448f567c7f..db3c9dc0fdf62 100644 --- a/shell/common/shell_test_platform_view.cc +++ b/shell/common/shell_test_platform_view.cc @@ -20,40 +20,44 @@ namespace flutter { namespace testing { std::unique_ptr ShellTestPlatformView::Create( + BackendType backend, PlatformView::Delegate& delegate, const TaskRunners& task_runners, const std::shared_ptr& vsync_clock, const CreateVsyncWaiter& create_vsync_waiter, - BackendType backend, const std::shared_ptr& shell_test_external_view_embedder, const std::shared_ptr& is_gpu_disabled_sync_switch) { // TODO(gw280): https://github.com/flutter/flutter/issues/50298 // Make this fully runtime configurable switch (backend) { - case BackendType::kDefaultBackend: -#ifdef SHELL_ENABLE_GL case BackendType::kGLBackend: +#ifdef SHELL_ENABLE_GL return std::make_unique( delegate, task_runners, vsync_clock, create_vsync_waiter, shell_test_external_view_embedder); +#else + FML_LOG(FATAL) << "OpenGL not enabled in this build"; + return nullptr; #endif // SHELL_ENABLE_GL -#ifdef SHELL_ENABLE_VULKAN case BackendType::kVulkanBackend: +#ifdef SHELL_ENABLE_VULKAN return std::make_unique( delegate, task_runners, vsync_clock, create_vsync_waiter, shell_test_external_view_embedder); +#else + FML_LOG(FATAL) << "Vulkan not enabled in this build"; + return nullptr; #endif // SHELL_ENABLE_VULKAN -#ifdef SHELL_ENABLE_METAL case BackendType::kMetalBackend: +#ifdef SHELL_ENABLE_METAL return std::make_unique( delegate, task_runners, vsync_clock, create_vsync_waiter, shell_test_external_view_embedder, is_gpu_disabled_sync_switch); -#endif // SHELL_ENABLE_METAL - - default: - FML_LOG(FATAL) << "No backends supported for ShellTestPlatformView"; +#else + FML_LOG(FATAL) << "Metal not enabled in this build"; return nullptr; +#endif // SHELL_ENABLE_METAL } } @@ -76,11 +80,11 @@ std::unique_ptr ShellTestPlatformViewBuilder::operator()( } }; return ShellTestPlatformView::Create( + config_.rendering_backend, // shell, // task_runners, // vsync_clock, // create_vsync_waiter, // - config_.rendering_backend, // config_.shell_test_external_view_embedder, // shell.GetIsGpuDisabledSyncSwitch() // ); diff --git a/shell/common/shell_test_platform_view.h b/shell/common/shell_test_platform_view.h index 459476c668bf2..2e8f8e34cb974 100644 --- a/shell/common/shell_test_platform_view.h +++ b/shell/common/shell_test_platform_view.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_H_ #define FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_H_ +#include + #include "flutter/shell/common/platform_view.h" #include "flutter/shell/common/shell_test_external_view_embedder.h" #include "flutter/shell/common/vsync_waiters_test.h" @@ -15,18 +17,30 @@ namespace testing { class ShellTestPlatformView : public PlatformView { public: enum class BackendType { - kDefaultBackend = 0, kGLBackend, kVulkanBackend, kMetalBackend, }; + static BackendType DefaultBackendType() { +#if defined(SHELL_ENABLE_GL) + return BackendType::kGLBackend; +#elif defined(SHELL_ENABLE_METAL) + return BackendType::kMetalBackend; +#elif defined(SHELL_ENABLE_VULKAN) + return BackendType::kVulkanBackend; +#else + FML_LOG(FATAL) << "No backend is enabled in this build."; + std::terminate(); +#endif + } + static std::unique_ptr Create( + BackendType backend, PlatformView::Delegate& delegate, const TaskRunners& task_runners, const std::shared_ptr& vsync_clock, const CreateVsyncWaiter& create_vsync_waiter, - BackendType backend, const std::shared_ptr& shell_test_external_view_embedder, const std::shared_ptr& @@ -50,7 +64,7 @@ class ShellTestPlatformViewBuilder { std::shared_ptr shell_test_external_view_embedder = nullptr; ShellTestPlatformView::BackendType rendering_backend = - ShellTestPlatformView::BackendType::kDefaultBackend; + ShellTestPlatformView::DefaultBackendType(); }; explicit ShellTestPlatformViewBuilder(Config config); diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 3621646601a36..27424e721bee7 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -500,13 +500,13 @@ TEST_F(ShellTest, // vsync mechanism. We should have better DI in the tests. const auto vsync_clock = std::make_shared(); return ShellTestPlatformView::Create( - shell, shell.GetTaskRunners(), vsync_clock, + ShellTestPlatformView::DefaultBackendType(), shell, + shell.GetTaskRunners(), vsync_clock, [task_runners = shell.GetTaskRunners()]() { return static_cast>( std::make_unique(task_runners)); }, - ShellTestPlatformView::BackendType::kDefaultBackend, nullptr, - shell.GetIsGpuDisabledSyncSwitch()); + nullptr, shell.GetIsGpuDisabledSyncSwitch()); }, [](Shell& shell) { return std::make_unique(shell); }); ASSERT_TRUE(ValidateShell(shell.get()));