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

Commit 52e950c

Browse files
authored
Embedder: Refactor EmbedderTestContext creation (#56563)
Extracts creation of graphics backend specfic EmbedderTestContext creation to their own translation units. In particular, this allows for less conditional header includes, and more specifically, for code relating to the Metal backend to include headers that include Objective-C types -- today we cast these all to void* to avoid declaring them in headers, which requires special handling for ARC. An alternative approach would have been to extract backend-specific subclasses, but there are test suites such as `EmbedderTestMultiBackend` that are executed against multiple backends, which make that approach impractical. No test changes since this patch makes no semantic changes. Issue: flutter/flutter#137801 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 96ada4a commit 52e950c

File tree

6 files changed

+94
-37
lines changed

6 files changed

+94
-37
lines changed

shell/platform/embedder/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ if (enable_unittests) {
317317
"tests/embedder_test_compositor_gl.h",
318318
"tests/embedder_test_context_gl.cc",
319319
"tests/embedder_test_context_gl.h",
320+
"tests/embedder_test_gl.cc",
320321
]
321322

322323
public_deps += [
@@ -331,6 +332,7 @@ if (enable_unittests) {
331332
"tests/embedder_test_compositor_metal.h",
332333
"tests/embedder_test_context_metal.cc",
333334
"tests/embedder_test_context_metal.h",
335+
"tests/embedder_test_metal.mm",
334336
]
335337

336338
public_deps += [ "//flutter/testing:metal" ]
@@ -342,6 +344,7 @@ if (enable_unittests) {
342344
"tests/embedder_test_compositor_vulkan.h",
343345
"tests/embedder_test_context_vulkan.cc",
344346
"tests/embedder_test_context_vulkan.h",
347+
"tests/embedder_test_vulkan.cc",
345348
]
346349

347350
public_deps += [

shell/platform/embedder/tests/embedder_test.cc

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,7 @@
55
#include "flutter/shell/platform/embedder/tests/embedder_test.h"
66
#include "flutter/shell/platform/embedder/tests/embedder_test_context_software.h"
77

8-
#ifdef SHELL_ENABLE_GL
9-
#include "flutter/shell/platform/embedder/tests/embedder_test_context_gl.h"
10-
#endif
11-
12-
#ifdef SHELL_ENABLE_METAL
13-
#include "flutter/shell/platform/embedder/tests/embedder_test_context_metal.h"
14-
#endif
15-
16-
#ifdef SHELL_ENABLE_VULKAN
17-
#include "flutter/shell/platform/embedder/tests/embedder_test_context_vulkan.h"
18-
#endif
19-
20-
namespace flutter {
21-
namespace testing {
8+
namespace flutter::testing {
229

2310
EmbedderTest::EmbedderTest() = default;
2411

@@ -33,28 +20,17 @@ EmbedderTestContext& EmbedderTest::GetEmbedderContext(
3320
if (!embedder_contexts_[type]) {
3421
switch (type) {
3522
case EmbedderTestContextType::kSoftwareContext:
36-
embedder_contexts_[type] =
37-
std::make_unique<EmbedderTestContextSoftware>(
38-
GetFixturesDirectory());
23+
embedder_contexts_[type] = CreateSoftwareContext();
3924
break;
40-
#ifdef SHELL_ENABLE_VULKAN
41-
case EmbedderTestContextType::kVulkanContext:
42-
embedder_contexts_[type] =
43-
std::make_unique<EmbedderTestContextVulkan>(GetFixturesDirectory());
44-
break;
45-
#endif
46-
#ifdef SHELL_ENABLE_GL
4725
case EmbedderTestContextType::kOpenGLContext:
48-
embedder_contexts_[type] =
49-
std::make_unique<EmbedderTestContextGL>(GetFixturesDirectory());
26+
embedder_contexts_[type] = CreateGLContext();
27+
break;
28+
case EmbedderTestContextType::kVulkanContext:
29+
embedder_contexts_[type] = CreateVulkanContext();
5030
break;
51-
#endif
52-
#ifdef SHELL_ENABLE_METAL
5331
case EmbedderTestContextType::kMetalContext:
54-
embedder_contexts_[type] =
55-
std::make_unique<EmbedderTestContextMetal>(GetFixturesDirectory());
32+
embedder_contexts_[type] = CreateMetalContext();
5633
break;
57-
#endif
5834
default:
5935
FML_DCHECK(false) << "Invalid context type specified.";
6036
break;
@@ -64,5 +40,35 @@ EmbedderTestContext& EmbedderTest::GetEmbedderContext(
6440
return *embedder_contexts_[type];
6541
}
6642

67-
} // namespace testing
68-
} // namespace flutter
43+
std::unique_ptr<EmbedderTestContext> EmbedderTest::CreateSoftwareContext() {
44+
return std::make_unique<EmbedderTestContextSoftware>(GetFixturesDirectory());
45+
}
46+
47+
#ifndef SHELL_ENABLE_GL
48+
// Fallback implementation.
49+
// See: flutter/shell/platform/embedder/tests/embedder_test_gl.cc.
50+
std::unique_ptr<EmbedderTestContext> EmbedderTest::CreateGLContext() {
51+
FML_LOG(FATAL) << "OpenGL is not supported in this build";
52+
return nullptr;
53+
}
54+
#endif
55+
56+
#ifndef SHELL_ENABLE_METAL
57+
// Fallback implementation.
58+
// See: flutter/shell/platform/embedder/tests/embedder_test_metal.mm.
59+
std::unique_ptr<EmbedderTestContext> EmbedderTest::CreateMetalContext() {
60+
FML_LOG(FATAL) << "Metal is not supported in this build";
61+
return nullptr;
62+
}
63+
#endif
64+
65+
#ifndef SHELL_ENABLE_VULKAN
66+
// Fallback implementation.
67+
// See: flutter/shell/platform/embedder/tests/embedder_test_vulkan.cc.
68+
std::unique_ptr<EmbedderTestContext> EmbedderTest::CreateVulkanContext() {
69+
FML_LOG(FATAL) << "Vulkan is not supported in this build";
70+
return nullptr;
71+
}
72+
#endif
73+
74+
} // namespace flutter::testing

shell/platform/embedder/tests/embedder_test.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
#include "flutter/testing/thread_test.h"
1515
#include "gtest/gtest.h"
1616

17-
namespace flutter {
18-
namespace testing {
17+
namespace flutter::testing {
1918

2019
class EmbedderTest : public ThreadTest {
2120
public:
@@ -29,14 +28,18 @@ class EmbedderTest : public ThreadTest {
2928
std::map<EmbedderTestContextType, std::unique_ptr<EmbedderTestContext>>
3029
embedder_contexts_;
3130

31+
std::unique_ptr<EmbedderTestContext> CreateSoftwareContext();
32+
std::unique_ptr<EmbedderTestContext> CreateGLContext();
33+
std::unique_ptr<EmbedderTestContext> CreateMetalContext();
34+
std::unique_ptr<EmbedderTestContext> CreateVulkanContext();
35+
3236
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderTest);
3337
};
3438

3539
class EmbedderTestMultiBackend
3640
: public EmbedderTest,
3741
public ::testing::WithParamInterface<EmbedderTestContextType> {};
3842

39-
} // namespace testing
40-
} // namespace flutter
43+
} // namespace flutter::testing
4144

4245
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_H_
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
5+
#include "flutter/shell/platform/embedder/tests/embedder_test.h"
6+
7+
#include "flutter/shell/platform/embedder/tests/embedder_test_context_gl.h"
8+
9+
namespace flutter::testing {
10+
11+
std::unique_ptr<EmbedderTestContext> EmbedderTest::CreateGLContext() {
12+
return std::make_unique<EmbedderTestContextGL>(GetFixturesDirectory());
13+
}
14+
15+
} // namespace flutter::testing
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
5+
#include "flutter/shell/platform/embedder/tests/embedder_test.h"
6+
7+
#include "flutter/shell/platform/embedder/tests/embedder_test_context_metal.h"
8+
9+
namespace flutter::testing {
10+
11+
std::unique_ptr<EmbedderTestContext> EmbedderTest::CreateMetalContext() {
12+
return std::make_unique<EmbedderTestContextMetal>(GetFixturesDirectory());
13+
}
14+
15+
} // namespace flutter::testing
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
5+
#include "flutter/shell/platform/embedder/tests/embedder_test.h"
6+
7+
#include "flutter/shell/platform/embedder/tests/embedder_test_context_vulkan.h"
8+
9+
namespace flutter::testing {
10+
11+
std::unique_ptr<EmbedderTestContext> EmbedderTest::CreateVulkanContext() {
12+
return std::make_unique<EmbedderTestContextVulkan>(GetFixturesDirectory());
13+
}
14+
15+
} // namespace flutter::testing

0 commit comments

Comments
 (0)