[engine] add an ios noop context. (flutter/engine#54856)

This is required to allow simulators to run without exiting when impeller is enabled and there is no available metal contxt.
This commit is contained in:
Jonah Williams
2024-08-28 22:07:24 -07:00
committed by GitHub
parent 4385a96ee1
commit 95d3280800
7 changed files with 140 additions and 5 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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",
]

View File

@@ -3,11 +3,13 @@
// found in the LICENSE file.
#include "flutter/shell/platform/darwin/ios/ios_context.h"
#include <memory>
#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> IOSContext::Create(
const std::shared_ptr<const fml::SyncSwitch>& 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<IOSContextNoop>();
}
return std::make_unique<IOSContextSoftware>();
case IOSRenderingAPI::kMetal:
switch (backend) {

View File

@@ -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<GrDirectContext> CreateResourceContext() override;
// |IOSContext|
sk_sp<GrDirectContext> GetMainContext() const override;
// |IOSContext|
std::unique_ptr<GLContextResult> MakeCurrent() override;
// |IOSContext|
std::unique_ptr<Texture> CreateExternalTexture(
int64_t texture_id,
fml::scoped_nsobject<NSObject<FlutterTexture>> 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_

View File

@@ -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<GrDirectContext> IOSContextNoop::CreateResourceContext() {
return nullptr;
}
// |IOSContext|
sk_sp<GrDirectContext> IOSContextNoop::GetMainContext() const {
return nullptr;
}
// |IOSContext|
IOSRenderingBackend IOSContextNoop::GetBackend() const {
return IOSRenderingBackend::kImpeller;
}
// |IOSContext|
std::unique_ptr<GLContextResult> IOSContextNoop::MakeCurrent() {
// This only makes sense for context that need to be bound to a specific thread.
return std::make_unique<GLContextDefaultResult>(false);
}
// |IOSContext|
std::unique_ptr<Texture> IOSContextNoop::CreateExternalTexture(
int64_t texture_id,
fml::scoped_nsobject<NSObject<FlutterTexture>> 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

View File

@@ -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 <QuartzCore/QuartzCore.h>
#import <XCTest/XCTest.h>
#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