diff --git a/engine/src/flutter/ci/licenses_golden/excluded_files b/engine/src/flutter/ci/licenses_golden/excluded_files index 0053a789b8..8d1faa024b 100644 --- a/engine/src/flutter/ci/licenses_golden/excluded_files +++ b/engine/src/flutter/ci/licenses_golden/excluded_files @@ -337,6 +337,7 @@ ../../../flutter/shell/platform/darwin/common/availability_version_check_unittests.cc ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_codecs_unittest.mm ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_standard_codec_unittest.mm +../../../flutter/shell/platform/darwin/ios/ios_context_noop_unittests.mm ../../../flutter/shell/platform/darwin/ios/ios_surface_noop_unittests.mm ../../../flutter/shell/platform/darwin/macos/README.md ../../../flutter/shell/platform/darwin/macos/framework/Source/fixtures diff --git a/engine/src/flutter/ci/licenses_golden/licenses_flutter b/engine/src/flutter/ci/licenses_golden/licenses_flutter index e3bba96226..653a2f5cc8 100644 --- a/engine/src/flutter/ci/licenses_golden/licenses_flutter +++ b/engine/src/flutter/ci/licenses_golden/licenses_flutter @@ -44436,6 +44436,8 @@ ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_impeller.h ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_impeller.mm + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_skia.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_context_noop.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_context_noop.mm + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_context_software.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_context_software.mm + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/ios/ios_external_texture_metal.h + ../../../flutter/LICENSE @@ -47342,6 +47344,8 @@ FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_impeller.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_impeller.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_skia.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm +FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_noop.h +FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_noop.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_software.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_software.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_external_texture_metal.h diff --git a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn index 10fcaab633..7b821c2d94 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/ios/BUILD.gn @@ -125,6 +125,8 @@ source_set("flutter_framework_source_arc") { "ios_context_metal_impeller.mm", "ios_context_metal_skia.h", "ios_context_metal_skia.mm", + "ios_context_noop.h", + "ios_context_noop.mm", "ios_context_software.h", "ios_context_software.mm", "ios_external_texture_metal.h", @@ -286,6 +288,7 @@ shared_library("ios_test_flutter") { "framework/Source/accessibility_bridge_test.mm", "framework/Source/availability_version_check_test.mm", "framework/Source/connection_collection_test.mm", + "ios_context_noop_unittests.mm", "ios_surface_noop_unittests.mm", "platform_message_handler_ios_test.mm", ] diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_context.mm index 7ddd252b64..ac6db41aa5 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context.mm @@ -3,11 +3,13 @@ // found in the LICENSE file. #include "flutter/shell/platform/darwin/ios/ios_context.h" +#include #include "flutter/shell/platform/darwin/ios/rendering_api_selection.h" #include "flutter/fml/logging.h" #include "flutter/shell/platform/darwin/ios/ios_context_metal_impeller.h" #include "flutter/shell/platform/darwin/ios/ios_context_metal_skia.h" +#include "flutter/shell/platform/darwin/ios/ios_context_noop.h" #include "flutter/shell/platform/darwin/ios/ios_context_software.h" FLUTTER_ASSERT_ARC @@ -24,11 +26,15 @@ std::unique_ptr IOSContext::Create( const std::shared_ptr& is_gpu_disabled_sync_switch) { switch (api) { case IOSRenderingAPI::kSoftware: - FML_CHECK(backend != IOSRenderingBackend::kImpeller) - << "Software rendering is incompatible with Impeller.\n" - "Software rendering may have been automatically selected when running on a simulator " - "in an environment that does not support Metal. Enabling GPU pass through in your " - "environment may fix this. If that is not possible, then disable Impeller."; + if (backend == IOSRenderingBackend::kImpeller) { + FML_LOG(IMPORTANT) + << "Software rendering is incompatible with Impeller.\n" + "Software rendering may have been automatically selected when running on a " + "simulator " + "in an environment that does not support Metal. Enabling GPU passthrough in your " + "environment may fix this."; + return std::make_unique(); + } return std::make_unique(); case IOSRenderingAPI::kMetal: switch (backend) { diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context_noop.h b/engine/src/flutter/shell/platform/darwin/ios/ios_context_noop.h new file mode 100644 index 0000000000..b4c8ec9fe4 --- /dev/null +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context_noop.h @@ -0,0 +1,44 @@ +// 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. + +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_NOOP_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_NOOP_H_ + +#import "flutter/shell/platform/darwin/ios/ios_context.h" + +namespace flutter { + +/// @brief A noop rendering context for usage on simulators without metal support. +class IOSContextNoop final : public IOSContext { + public: + IOSContextNoop(); + + // |IOSContext| + ~IOSContextNoop(); + + // |IOSContext| + sk_sp CreateResourceContext() override; + + // |IOSContext| + sk_sp GetMainContext() const override; + + // |IOSContext| + std::unique_ptr MakeCurrent() override; + + // |IOSContext| + std::unique_ptr CreateExternalTexture( + int64_t texture_id, + fml::scoped_nsobject> texture) override; + + IOSRenderingBackend GetBackend() const override; + + private: + IOSContextNoop(const IOSContextNoop&) = delete; + + IOSContextNoop& operator=(const IOSContextNoop&) = delete; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_NOOP_H_ diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context_noop.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_context_noop.mm new file mode 100644 index 0000000000..1a083eb470 --- /dev/null +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context_noop.mm @@ -0,0 +1,53 @@ +// 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. + +#import "flutter/shell/platform/darwin/ios/ios_context_noop.h" +#include "ios_context.h" +#include "shell/platform/darwin/ios/rendering_api_selection.h" + +FLUTTER_ASSERT_ARC + +namespace flutter { + +IOSContextNoop::IOSContextNoop() = default; + +// |IOSContext| +IOSContextNoop::~IOSContextNoop() = default; + +// |IOSContext| +sk_sp IOSContextNoop::CreateResourceContext() { + return nullptr; +} + +// |IOSContext| +sk_sp IOSContextNoop::GetMainContext() const { + return nullptr; +} + +// |IOSContext| +IOSRenderingBackend IOSContextNoop::GetBackend() const { + return IOSRenderingBackend::kImpeller; +} + +// |IOSContext| +std::unique_ptr IOSContextNoop::MakeCurrent() { + // This only makes sense for context that need to be bound to a specific thread. + return std::make_unique(false); +} + +// |IOSContext| +std::unique_ptr IOSContextNoop::CreateExternalTexture( + int64_t texture_id, + fml::scoped_nsobject> texture) { + // Don't use FML for logging as it will contain engine specific details. This is a user facing + // message. + NSLog(@"Flutter: Attempted to composite external texture sources using the noop backend. " + @"This backend is only used on simulators. This feature is only available on actual " + @"devices where Metal is used for rendering."); + + // Not supported in this backend. + return nullptr; +} + +} // namespace flutter diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context_noop_unittests.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_context_noop_unittests.mm new file mode 100644 index 0000000000..f5c882f150 --- /dev/null +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context_noop_unittests.mm @@ -0,0 +1,24 @@ +// 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 +#import + +#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h" +#include "shell/platform/darwin/ios/ios_context_noop.h" +#include "shell/platform/darwin/ios/rendering_api_selection.h" + +FLUTTER_ASSERT_ARC + +@interface IOSContextNoopTest : XCTestCase +@end + +@implementation IOSContextNoopTest +- (void)testCreateNoop { + flutter::IOSContextNoop noop; + + XCTAssertTrue(noop.GetBackend() == flutter::IOSRenderingBackend::kImpeller); +} + +@end