Skip to content

Commit 34b7c2d

Browse files
committed
Extract backend-specific code in ShellTestPlatformView
Moves code specific to each graphics backend into the (existing) translation unit associated with that backend. Previously, we could not include any Objective-C types in shell_test_platform_view_metal.h, since that file was included into shell_test_platform_view.cc, which is pure C++. To work around this, we had encapsulated Objective-C Metal types in a `DarwinContextMetal` struct hidden in the implementation file with a pointer to it forward-declared in the header. We now use Metal types directly in the header, without the workarounds. Issue: flutter/flutter#158998 Issue: flutter/flutter#137801
1 parent 3f19207 commit 34b7c2d

8 files changed

+172
-103
lines changed

shell/common/shell_test_platform_view.cc

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,9 @@
44

55
#include "flutter/shell/common/shell_test_platform_view.h"
66

7-
#ifdef SHELL_ENABLE_GL
8-
#include "flutter/shell/common/shell_test_platform_view_gl.h"
9-
#endif // SHELL_ENABLE_GL
10-
#ifdef SHELL_ENABLE_VULKAN
11-
#include "flutter/shell/common/shell_test_platform_view_vulkan.h"
12-
#endif // SHELL_ENABLE_VULKAN
13-
#ifdef SHELL_ENABLE_METAL
14-
#include "flutter/shell/common/shell_test_platform_view_metal.h"
15-
#endif // SHELL_ENABLE_METAL
16-
177
#include "flutter/shell/common/vsync_waiter_fallback.h"
188

19-
namespace flutter {
20-
namespace testing {
9+
namespace flutter::testing {
2110

2211
std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
2312
PlatformView::Delegate& delegate,
@@ -32,28 +21,18 @@ std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
3221
// Make this fully runtime configurable
3322
switch (backend) {
3423
case BackendType::kDefaultBackend:
35-
#ifdef SHELL_ENABLE_GL
3624
case BackendType::kGLBackend:
37-
return std::make_unique<ShellTestPlatformViewGL>(
25+
return CreatePlatformViewGL(
3826
delegate, task_runners, vsync_clock, create_vsync_waiter,
39-
shell_test_external_view_embedder);
40-
#endif // SHELL_ENABLE_GL
41-
#ifdef SHELL_ENABLE_VULKAN
27+
shell_test_external_view_embedder, is_gpu_disabled_sync_switch);
4228
case BackendType::kVulkanBackend:
43-
return std::make_unique<ShellTestPlatformViewVulkan>(
29+
return CreatePlatformViewVulkan(
4430
delegate, task_runners, vsync_clock, create_vsync_waiter,
45-
shell_test_external_view_embedder);
46-
#endif // SHELL_ENABLE_VULKAN
47-
#ifdef SHELL_ENABLE_METAL
31+
shell_test_external_view_embedder, is_gpu_disabled_sync_switch);
4832
case BackendType::kMetalBackend:
49-
return std::make_unique<ShellTestPlatformViewMetal>(
33+
return CreatePlatformViewMetal(
5034
delegate, task_runners, vsync_clock, create_vsync_waiter,
5135
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";
56-
return nullptr;
5736
}
5837
}
5938

@@ -86,5 +65,50 @@ std::unique_ptr<PlatformView> ShellTestPlatformViewBuilder::operator()(
8665
);
8766
}
8867

89-
} // namespace testing
90-
} // namespace flutter
68+
#ifndef SHELL_ENABLE_GL
69+
// Fallback implementation.
70+
// See: flutter/shell/common/shell_test_platform_view_gl.cc
71+
std::unique_ptr<ShellTestPlatformView>
72+
ShellTestPlatformView::CreatePlatformViewGL(
73+
PlatformView::Delegate& delegate,
74+
const TaskRunners& task_runners,
75+
const std::shared_ptr<ShellTestVsyncClock>& vsync_clock,
76+
const CreateVsyncWaiter& create_vsync_waiter,
77+
const std::shared_ptr<ShellTestExternalViewEmbedder>&
78+
shell_test_external_view_embedder,
79+
const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch) {
80+
return nullptr;
81+
}
82+
#endif // SHELL_ENABLE_GL
83+
#ifndef SHELL_ENABLE_METAL
84+
// Fallback implementation.
85+
// See: flutter/shell/common/shell_test_platform_view_metal.mm
86+
std::unique_ptr<ShellTestPlatformView>
87+
ShellTestPlatformView::CreatePlatformViewMetal(
88+
PlatformView::Delegate& delegate,
89+
const TaskRunners& task_runners,
90+
const std::shared_ptr<ShellTestVsyncClock>& vsync_clock,
91+
const CreateVsyncWaiter& create_vsync_waiter,
92+
const std::shared_ptr<ShellTestExternalViewEmbedder>&
93+
shell_test_external_view_embedder,
94+
const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch) {
95+
return nullptr;
96+
}
97+
#endif // SHELL_ENABLE_METAL
98+
#ifndef SHELL_ENABLE_VULKAN
99+
// Fallback implementation.
100+
// See: flutter/shell/common/shell_test_platform_view_vulkan.cc
101+
std::unique_ptr<ShellTestPlatformView>
102+
ShellTestPlatformView::CreatePlatformViewVulkan(
103+
PlatformView::Delegate& delegate,
104+
const TaskRunners& task_runners,
105+
const std::shared_ptr<ShellTestVsyncClock>& vsync_clock,
106+
const CreateVsyncWaiter& create_vsync_waiter,
107+
const std::shared_ptr<ShellTestExternalViewEmbedder>&
108+
shell_test_external_view_embedder,
109+
const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch) {
110+
return nullptr;
111+
}
112+
#endif // SHELL_ENABLE_VULKAN
113+
114+
} // namespace flutter::testing

shell/common/shell_test_platform_view.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
#include "flutter/shell/common/shell_test_external_view_embedder.h"
1010
#include "flutter/shell/common/vsync_waiters_test.h"
1111

12-
namespace flutter {
13-
namespace testing {
12+
namespace flutter::testing {
1413

1514
class ShellTestPlatformView : public PlatformView {
1615
public:
@@ -39,6 +38,35 @@ class ShellTestPlatformView : public PlatformView {
3938
const TaskRunners& task_runners)
4039
: PlatformView(delegate, task_runners) {}
4140

41+
private:
42+
static std::unique_ptr<ShellTestPlatformView> CreatePlatformViewGL(
43+
PlatformView::Delegate& delegate,
44+
const TaskRunners& task_runners,
45+
const std::shared_ptr<ShellTestVsyncClock>& vsync_clock,
46+
const CreateVsyncWaiter& create_vsync_waiter,
47+
const std::shared_ptr<ShellTestExternalViewEmbedder>&
48+
shell_test_external_view_embedder,
49+
const std::shared_ptr<const fml::SyncSwitch>&
50+
is_gpu_disabled_sync_switch);
51+
static std::unique_ptr<ShellTestPlatformView> CreatePlatformViewMetal(
52+
PlatformView::Delegate& delegate,
53+
const TaskRunners& task_runners,
54+
const std::shared_ptr<ShellTestVsyncClock>& vsync_clock,
55+
const CreateVsyncWaiter& create_vsync_waiter,
56+
const std::shared_ptr<ShellTestExternalViewEmbedder>&
57+
shell_test_external_view_embedder,
58+
const std::shared_ptr<const fml::SyncSwitch>&
59+
is_gpu_disabled_sync_switch);
60+
static std::unique_ptr<ShellTestPlatformView> CreatePlatformViewVulkan(
61+
PlatformView::Delegate& delegate,
62+
const TaskRunners& task_runners,
63+
const std::shared_ptr<ShellTestVsyncClock>& vsync_clock,
64+
const CreateVsyncWaiter& create_vsync_waiter,
65+
const std::shared_ptr<ShellTestExternalViewEmbedder>&
66+
shell_test_external_view_embedder,
67+
const std::shared_ptr<const fml::SyncSwitch>&
68+
is_gpu_disabled_sync_switch);
69+
4270
FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView);
4371
};
4472

@@ -63,7 +91,6 @@ class ShellTestPlatformViewBuilder {
6391
Config config_;
6492
};
6593

66-
} // namespace testing
67-
} // namespace flutter
94+
} // namespace flutter::testing
6895

6996
#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_H_

shell/common/shell_test_platform_view_gl.cc

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@
88

99
#include <EGL/egl.h>
1010

11+
#include "flutter/shell/common/shell_test_platform_view_gl.h"
1112
#include "flutter/shell/gpu/gpu_surface_gl_skia.h"
1213
#include "impeller/entity/gles/entity_shaders_gles.h"
1314

14-
namespace flutter {
15-
namespace testing {
15+
namespace flutter::testing {
1616

17-
static std::vector<std::shared_ptr<fml::Mapping>> ShaderLibraryMappings() {
17+
namespace {
18+
std::vector<std::shared_ptr<fml::Mapping>> ShaderLibraryMappings() {
1819
return {
1920
std::make_shared<fml::NonOwnedMapping>(
2021
impeller_entity_shaders_gles_data,
2122
impeller_entity_shaders_gles_length),
2223
};
2324
}
25+
} // namespace
26+
27+
std::unique_ptr<ShellTestPlatformView>
28+
ShellTestPlatformView::CreatePlatformViewGL(
29+
PlatformView::Delegate& delegate,
30+
const TaskRunners& task_runners,
31+
const std::shared_ptr<ShellTestVsyncClock>& vsync_clock,
32+
const CreateVsyncWaiter& create_vsync_waiter,
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<ShellTestPlatformViewGL>(
37+
delegate, task_runners, vsync_clock, create_vsync_waiter,
38+
shell_test_external_view_embedder);
39+
}
2440

2541
ShellTestPlatformViewGL::ShellTestPlatformViewGL(
2642
PlatformView::Delegate& delegate,
@@ -113,5 +129,4 @@ ShellTestPlatformViewGL::GetGLProcResolver() const {
113129
};
114130
}
115131

116-
} // namespace testing
117-
} // namespace flutter
132+
} // namespace flutter::testing

shell/common/shell_test_platform_view_gl.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
#include "flutter/testing/test_gl_surface.h"
1212
#include "impeller/renderer/backend/gles/context_gles.h"
1313

14-
namespace flutter {
15-
namespace testing {
14+
namespace flutter::testing {
1615

1716
class ShellTestPlatformViewGL : public ShellTestPlatformView,
1817
public GPUSurfaceGLDelegate {
@@ -77,7 +76,6 @@ class ShellTestPlatformViewGL : public ShellTestPlatformView,
7776
FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformViewGL);
7877
};
7978

80-
} // namespace testing
81-
} // namespace flutter
79+
} // namespace flutter::testing
8280

8381
#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_GL_H_

shell/common/shell_test_platform_view_metal.h

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

8-
#include "flutter/fml/macros.h"
98
#include "flutter/shell/common/shell_test_platform_view.h"
10-
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
119

12-
namespace flutter {
13-
namespace testing {
10+
#import <Metal/Metal.h>
11+
12+
#include "flutter/fml/macros.h"
13+
#include "flutter/shell/gpu/gpu_surface_metal_delegate.h"
14+
#include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h"
15+
#include "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
1416

15-
struct DarwinContextMetal;
17+
namespace flutter::testing {
1618

1719
class ShellTestPlatformViewMetal final : public ShellTestPlatformView,
1820
public GPUSurfaceMetalDelegate {
@@ -30,7 +32,9 @@ class ShellTestPlatformViewMetal final : public ShellTestPlatformView,
3032
virtual ~ShellTestPlatformViewMetal() override;
3133

3234
private:
33-
const std::unique_ptr<DarwinContextMetal> metal_context_;
35+
FlutterDarwinContextMetalSkia* skia_context_;
36+
FlutterDarwinContextMetalImpeller* impeller_context_;
37+
id<MTLTexture> offscreen_texture_;
3438
const CreateVsyncWaiter create_vsync_waiter_;
3539
const std::shared_ptr<ShellTestVsyncClock> vsync_clock_;
3640
const std::shared_ptr<ShellTestExternalViewEmbedder>
@@ -70,7 +74,6 @@ class ShellTestPlatformViewMetal final : public ShellTestPlatformView,
7074
FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformViewMetal);
7175
};
7276

73-
} // namespace testing
74-
} // namespace flutter
77+
} // namespace flutter::testing
7578

7679
#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_METAL_H_

0 commit comments

Comments
 (0)