From 702399494fdf9bca8696fc7438164f9399150230 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 13 Nov 2024 08:57:56 -0800 Subject: [PATCH 1/2] Embedder: Refactor EmbedderTestContext creation 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. Issue: https://github.com/flutter/flutter/issues/137801 --- shell/platform/embedder/BUILD.gn | 3 + .../platform/embedder/tests/embedder_test.cc | 66 +++++++++++-------- shell/platform/embedder/tests/embedder_test.h | 5 ++ .../embedder/tests/embedder_test_gl.cc | 17 +++++ .../embedder/tests/embedder_test_metal.mm | 17 +++++ .../embedder/tests/embedder_test_vulkan.cc | 17 +++++ 6 files changed, 96 insertions(+), 29 deletions(-) create mode 100644 shell/platform/embedder/tests/embedder_test_gl.cc create mode 100644 shell/platform/embedder/tests/embedder_test_metal.mm create mode 100644 shell/platform/embedder/tests/embedder_test_vulkan.cc diff --git a/shell/platform/embedder/BUILD.gn b/shell/platform/embedder/BUILD.gn index a0c1b25899b61..849bc8fcee454 100644 --- a/shell/platform/embedder/BUILD.gn +++ b/shell/platform/embedder/BUILD.gn @@ -317,6 +317,7 @@ if (enable_unittests) { "tests/embedder_test_compositor_gl.h", "tests/embedder_test_context_gl.cc", "tests/embedder_test_context_gl.h", + "tests/embedder_test_gl.cc", ] public_deps += [ @@ -331,6 +332,7 @@ if (enable_unittests) { "tests/embedder_test_compositor_metal.h", "tests/embedder_test_context_metal.cc", "tests/embedder_test_context_metal.h", + "tests/embedder_test_metal.mm", ] public_deps += [ "//flutter/testing:metal" ] @@ -342,6 +344,7 @@ if (enable_unittests) { "tests/embedder_test_compositor_vulkan.h", "tests/embedder_test_context_vulkan.cc", "tests/embedder_test_context_vulkan.h", + "tests/embedder_test_vulkan.cc", ] public_deps += [ diff --git a/shell/platform/embedder/tests/embedder_test.cc b/shell/platform/embedder/tests/embedder_test.cc index 0b557d318e1ee..6472c43f798e0 100644 --- a/shell/platform/embedder/tests/embedder_test.cc +++ b/shell/platform/embedder/tests/embedder_test.cc @@ -5,18 +5,6 @@ #include "flutter/shell/platform/embedder/tests/embedder_test.h" #include "flutter/shell/platform/embedder/tests/embedder_test_context_software.h" -#ifdef SHELL_ENABLE_GL -#include "flutter/shell/platform/embedder/tests/embedder_test_context_gl.h" -#endif - -#ifdef SHELL_ENABLE_METAL -#include "flutter/shell/platform/embedder/tests/embedder_test_context_metal.h" -#endif - -#ifdef SHELL_ENABLE_VULKAN -#include "flutter/shell/platform/embedder/tests/embedder_test_context_vulkan.h" -#endif - namespace flutter { namespace testing { @@ -33,28 +21,17 @@ EmbedderTestContext& EmbedderTest::GetEmbedderContext( if (!embedder_contexts_[type]) { switch (type) { case EmbedderTestContextType::kSoftwareContext: - embedder_contexts_[type] = - std::make_unique( - GetFixturesDirectory()); + embedder_contexts_[type] = CreateSoftwareContext(); break; -#ifdef SHELL_ENABLE_VULKAN - case EmbedderTestContextType::kVulkanContext: - embedder_contexts_[type] = - std::make_unique(GetFixturesDirectory()); - break; -#endif -#ifdef SHELL_ENABLE_GL case EmbedderTestContextType::kOpenGLContext: - embedder_contexts_[type] = - std::make_unique(GetFixturesDirectory()); + embedder_contexts_[type] = CreateGLContext(); + break; + case EmbedderTestContextType::kVulkanContext: + embedder_contexts_[type] = CreateVulkanContext(); break; -#endif -#ifdef SHELL_ENABLE_METAL case EmbedderTestContextType::kMetalContext: - embedder_contexts_[type] = - std::make_unique(GetFixturesDirectory()); + embedder_contexts_[type] = CreateMetalContext(); break; -#endif default: FML_DCHECK(false) << "Invalid context type specified."; break; @@ -64,5 +41,36 @@ EmbedderTestContext& EmbedderTest::GetEmbedderContext( return *embedder_contexts_[type]; } +std::unique_ptr EmbedderTest::CreateSoftwareContext() { + return std::make_unique(GetFixturesDirectory()); +} + +#ifndef SHELL_ENABLE_GL +// Fallback implementation. +// See: flutter/shell/platform/embedder/tests/embedder_test_gl.cc. +std::unique_ptr EmbedderTest::CreateGLContext() { + FML_LOG(FATAL) << "OpenGL is not supported in this build"; + return nullptr; +} +#endif + +#ifndef SHELL_ENABLE_METAL +// Fallback implementation. +// See: flutter/shell/platform/embedder/tests/embedder_test_metal.mm. +std::unique_ptr EmbedderTest::CreateMetalContext() { + FML_LOG(FATAL) << "Metal is not supported in this build"; + return nullptr; +} +#endif + +#ifndef SHELL_ENABLE_VULKAN +// Fallback implementation. +// See: flutter/shell/platform/embedder/tests/embedder_test_vulkan.cc. +std::unique_ptr EmbedderTest::CreateVulkanContext() { + FML_LOG(FATAL) << "Vulkan is not supported in this build"; + return nullptr; +} +#endif + } // namespace testing } // namespace flutter diff --git a/shell/platform/embedder/tests/embedder_test.h b/shell/platform/embedder/tests/embedder_test.h index eb16637872872..767a203a9859a 100644 --- a/shell/platform/embedder/tests/embedder_test.h +++ b/shell/platform/embedder/tests/embedder_test.h @@ -29,6 +29,11 @@ class EmbedderTest : public ThreadTest { std::map> embedder_contexts_; + std::unique_ptr CreateSoftwareContext(); + std::unique_ptr CreateGLContext(); + std::unique_ptr CreateMetalContext(); + std::unique_ptr CreateVulkanContext(); + FML_DISALLOW_COPY_AND_ASSIGN(EmbedderTest); }; diff --git a/shell/platform/embedder/tests/embedder_test_gl.cc b/shell/platform/embedder/tests/embedder_test_gl.cc new file mode 100644 index 0000000000000..ebd426fd6fd53 --- /dev/null +++ b/shell/platform/embedder/tests/embedder_test_gl.cc @@ -0,0 +1,17 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/embedder/tests/embedder_test.h" + +#include "flutter/shell/platform/embedder/tests/embedder_test_context_gl.h" + +namespace flutter { +namespace testing { + +std::unique_ptr EmbedderTest::CreateGLContext() { + return std::make_unique(GetFixturesDirectory()); +} + +} // namespace testing +} // namespace flutter diff --git a/shell/platform/embedder/tests/embedder_test_metal.mm b/shell/platform/embedder/tests/embedder_test_metal.mm new file mode 100644 index 0000000000000..116ad1b87d70b --- /dev/null +++ b/shell/platform/embedder/tests/embedder_test_metal.mm @@ -0,0 +1,17 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/embedder/tests/embedder_test.h" + +#include "flutter/shell/platform/embedder/tests/embedder_test_context_metal.h" + +namespace flutter { +namespace testing { + +std::unique_ptr EmbedderTest::CreateMetalContext() { + return std::make_unique(GetFixturesDirectory()); +} + +} // namespace testing +} // namespace flutter diff --git a/shell/platform/embedder/tests/embedder_test_vulkan.cc b/shell/platform/embedder/tests/embedder_test_vulkan.cc new file mode 100644 index 0000000000000..c3a7793318879 --- /dev/null +++ b/shell/platform/embedder/tests/embedder_test_vulkan.cc @@ -0,0 +1,17 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/embedder/tests/embedder_test.h" + +#include "flutter/shell/platform/embedder/tests/embedder_test_context_vulkan.h" + +namespace flutter { +namespace testing { + +std::unique_ptr EmbedderTest::CreateVulkanContext() { + return std::make_unique(GetFixturesDirectory()); +} + +} // namespace testing +} // namespace flutter From 7694624b97ded5028ea5bf004eab100908b6a2ae Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 13 Nov 2024 09:31:59 -0800 Subject: [PATCH 2/2] Update namespace notation --- shell/platform/embedder/tests/embedder_test.cc | 6 ++---- shell/platform/embedder/tests/embedder_test.h | 6 ++---- shell/platform/embedder/tests/embedder_test_gl.cc | 6 ++---- shell/platform/embedder/tests/embedder_test_metal.mm | 6 ++---- shell/platform/embedder/tests/embedder_test_vulkan.cc | 6 ++---- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/shell/platform/embedder/tests/embedder_test.cc b/shell/platform/embedder/tests/embedder_test.cc index 6472c43f798e0..10eb5595602a7 100644 --- a/shell/platform/embedder/tests/embedder_test.cc +++ b/shell/platform/embedder/tests/embedder_test.cc @@ -5,8 +5,7 @@ #include "flutter/shell/platform/embedder/tests/embedder_test.h" #include "flutter/shell/platform/embedder/tests/embedder_test_context_software.h" -namespace flutter { -namespace testing { +namespace flutter::testing { EmbedderTest::EmbedderTest() = default; @@ -72,5 +71,4 @@ std::unique_ptr EmbedderTest::CreateVulkanContext() { } #endif -} // namespace testing -} // namespace flutter +} // namespace flutter::testing diff --git a/shell/platform/embedder/tests/embedder_test.h b/shell/platform/embedder/tests/embedder_test.h index 767a203a9859a..4ba11ffdb4784 100644 --- a/shell/platform/embedder/tests/embedder_test.h +++ b/shell/platform/embedder/tests/embedder_test.h @@ -14,8 +14,7 @@ #include "flutter/testing/thread_test.h" #include "gtest/gtest.h" -namespace flutter { -namespace testing { +namespace flutter::testing { class EmbedderTest : public ThreadTest { public: @@ -41,7 +40,6 @@ class EmbedderTestMultiBackend : public EmbedderTest, public ::testing::WithParamInterface {}; -} // namespace testing -} // namespace flutter +} // namespace flutter::testing #endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_H_ diff --git a/shell/platform/embedder/tests/embedder_test_gl.cc b/shell/platform/embedder/tests/embedder_test_gl.cc index ebd426fd6fd53..6361437b57f92 100644 --- a/shell/platform/embedder/tests/embedder_test_gl.cc +++ b/shell/platform/embedder/tests/embedder_test_gl.cc @@ -6,12 +6,10 @@ #include "flutter/shell/platform/embedder/tests/embedder_test_context_gl.h" -namespace flutter { -namespace testing { +namespace flutter::testing { std::unique_ptr EmbedderTest::CreateGLContext() { return std::make_unique(GetFixturesDirectory()); } -} // namespace testing -} // namespace flutter +} // namespace flutter::testing diff --git a/shell/platform/embedder/tests/embedder_test_metal.mm b/shell/platform/embedder/tests/embedder_test_metal.mm index 116ad1b87d70b..63c210fced333 100644 --- a/shell/platform/embedder/tests/embedder_test_metal.mm +++ b/shell/platform/embedder/tests/embedder_test_metal.mm @@ -6,12 +6,10 @@ #include "flutter/shell/platform/embedder/tests/embedder_test_context_metal.h" -namespace flutter { -namespace testing { +namespace flutter::testing { std::unique_ptr EmbedderTest::CreateMetalContext() { return std::make_unique(GetFixturesDirectory()); } -} // namespace testing -} // namespace flutter +} // namespace flutter::testing diff --git a/shell/platform/embedder/tests/embedder_test_vulkan.cc b/shell/platform/embedder/tests/embedder_test_vulkan.cc index c3a7793318879..2dea4f6265679 100644 --- a/shell/platform/embedder/tests/embedder_test_vulkan.cc +++ b/shell/platform/embedder/tests/embedder_test_vulkan.cc @@ -6,12 +6,10 @@ #include "flutter/shell/platform/embedder/tests/embedder_test_context_vulkan.h" -namespace flutter { -namespace testing { +namespace flutter::testing { std::unique_ptr EmbedderTest::CreateVulkanContext() { return std::make_unique(GetFixturesDirectory()); } -} // namespace testing -} // namespace flutter +} // namespace flutter::testing