Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cb6ff1a

Browse files
committed
Eliminate ShellTestPlatformView::BackendType::kDefaultBackendType
`kDefaultBackendType` is intended to make life easier for authors of tests, but in any switch statement where it's used (currently just a single location), we rely on ordering it first and `#ifdef`ing out all backends that aren't available. Instead, we define a static function that returns the default that callers can invoke instead. This avoids relinace on case ordering and fallthrough. In #56722 we split backends out into separate translation units, and remove the `#ifdef`s which means we can't rely on this trick anymore.
1 parent 03eb3db commit cb6ff1a

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

shell/common/animator_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ TEST_F(ShellTest, VSyncTargetTime) {
8989
[vsync_clock, &create_vsync_waiter](Shell& shell) {
9090
return ShellTestPlatformView::Create(
9191
shell, shell.GetTaskRunners(), vsync_clock, create_vsync_waiter,
92-
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr,
92+
ShellTestPlatformView::DefaultBackendType(), nullptr,
9393
shell.GetIsGpuDisabledSyncSwitch());
9494
},
9595
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });

shell/common/shell_test_platform_view.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,33 @@ std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
3131
// TODO(gw280): https://github.com/flutter/flutter/issues/50298
3232
// Make this fully runtime configurable
3333
switch (backend) {
34-
case BackendType::kDefaultBackend:
35-
#ifdef SHELL_ENABLE_GL
3634
case BackendType::kGLBackend:
35+
#ifdef SHELL_ENABLE_GL
3736
return std::make_unique<ShellTestPlatformViewGL>(
3837
delegate, task_runners, vsync_clock, create_vsync_waiter,
3938
shell_test_external_view_embedder);
39+
#else
40+
FML_LOG(FATAL) << "OpenGL not enabled in this build";
41+
return nullptr;
4042
#endif // SHELL_ENABLE_GL
41-
#ifdef SHELL_ENABLE_VULKAN
4243
case BackendType::kVulkanBackend:
44+
#ifdef SHELL_ENABLE_VULKAN
4345
return std::make_unique<ShellTestPlatformViewVulkan>(
4446
delegate, task_runners, vsync_clock, create_vsync_waiter,
4547
shell_test_external_view_embedder);
48+
#else
49+
FML_LOG(FATAL) << "Vulkan not enabled in this build";
50+
return nullptr;
4651
#endif // SHELL_ENABLE_VULKAN
47-
#ifdef SHELL_ENABLE_METAL
4852
case BackendType::kMetalBackend:
53+
#ifdef SHELL_ENABLE_METAL
4954
return std::make_unique<ShellTestPlatformViewMetal>(
5055
delegate, task_runners, vsync_clock, create_vsync_waiter,
5156
shell_test_external_view_embedder, is_gpu_disabled_sync_switch);
52-
#endif // SHELL_ENABLE_METAL
53-
54-
default:
55-
FML_LOG(FATAL) << "No backends supported for ShellTestPlatformView";
57+
#else
58+
FML_LOG(FATAL) << "Metal not enabled in this build";
5659
return nullptr;
60+
#endif // SHELL_ENABLE_METAL
5761
}
5862
}
5963

shell/common/shell_test_platform_view.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_H_
66
#define FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_H_
77

8+
#include <exception>
9+
810
#include "flutter/shell/common/platform_view.h"
911
#include "flutter/shell/common/shell_test_external_view_embedder.h"
1012
#include "flutter/shell/common/vsync_waiters_test.h"
@@ -15,12 +17,24 @@ namespace testing {
1517
class ShellTestPlatformView : public PlatformView {
1618
public:
1719
enum class BackendType {
18-
kDefaultBackend = 0,
1920
kGLBackend,
2021
kVulkanBackend,
2122
kMetalBackend,
2223
};
2324

25+
static BackendType DefaultBackendType() {
26+
#if defined(SHELL_ENABLE_GL)
27+
return BackendType::kGLBackend;
28+
#elif defined(SHELL_ENABLE_METAL)
29+
return BackendType::kMetalBackend;
30+
#elif defined(SHELL_ENABLE_VULKAN)
31+
return BackendType::kMetalBackend;
32+
#else
33+
FML_LOG(FATAL) << "No backend is enabled in this build.";
34+
std::terminate();
35+
#endif
36+
}
37+
2438
static std::unique_ptr<ShellTestPlatformView> Create(
2539
PlatformView::Delegate& delegate,
2640
const TaskRunners& task_runners,
@@ -50,7 +64,7 @@ class ShellTestPlatformViewBuilder {
5064
std::shared_ptr<ShellTestExternalViewEmbedder>
5165
shell_test_external_view_embedder = nullptr;
5266
ShellTestPlatformView::BackendType rendering_backend =
53-
ShellTestPlatformView::BackendType::kDefaultBackend;
67+
ShellTestPlatformView::DefaultBackendType();
5468
};
5569

5670
explicit ShellTestPlatformViewBuilder(Config config);

shell/common/shell_unittests.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ TEST_F(ShellTest,
505505
return static_cast<std::unique_ptr<VsyncWaiter>>(
506506
std::make_unique<VsyncWaiterFallback>(task_runners));
507507
},
508-
ShellTestPlatformView::BackendType::kDefaultBackend, nullptr,
508+
ShellTestPlatformView::DefaultBackendType(), nullptr,
509509
shell.GetIsGpuDisabledSyncSwitch());
510510
},
511511
[](Shell& shell) { return std::make_unique<Rasterizer>(shell); });

0 commit comments

Comments
 (0)