From fd6330c74584ac8b9fb5f271b132c3a51c5642f5 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 19 May 2022 09:23:58 -0700 Subject: [PATCH] Revert "Enable MSAA behind a command line flag for iOS (#33461)" (flutter/engine#33481) This reverts commit ce9f6b2e43e2d88934345ac96bcb366a144b3408. --- .../common/shell_test_platform_view_metal.mm | 2 +- .../shell/gpu/gpu_surface_metal_skia.h | 2 -- .../shell/gpu/gpu_surface_metal_skia.mm | 26 +++++++++++-------- .../Source/FlutterEnginePlatformViewTest.mm | 25 +----------------- .../shell/platform/darwin/ios/ios_context.h | 17 ++---------- .../shell/platform/darwin/ios/ios_context.mm | 8 +++--- .../platform/darwin/ios/ios_context_gl.mm | 2 +- .../darwin/ios/ios_context_metal_impeller.mm | 3 +-- .../darwin/ios/ios_context_metal_skia.h | 2 +- .../darwin/ios/ios_context_metal_skia.mm | 2 +- .../darwin/ios/ios_context_software.mm | 3 +-- .../darwin/ios/ios_surface_metal_skia.mm | 5 ++-- .../platform/darwin/ios/platform_view_ios.mm | 16 +++++------- .../embedder/embedder_surface_metal.mm | 2 +- 14 files changed, 37 insertions(+), 78 deletions(-) diff --git a/engine/src/flutter/shell/common/shell_test_platform_view_metal.mm b/engine/src/flutter/shell/common/shell_test_platform_view_metal.mm index 79da2757fe..18869d69b8 100644 --- a/engine/src/flutter/shell/common/shell_test_platform_view_metal.mm +++ b/engine/src/flutter/shell/common/shell_test_platform_view_metal.mm @@ -91,7 +91,7 @@ PointerDataDispatcherMaker ShellTestPlatformViewMetal::GetDispatcherMaker() { // |PlatformView| std::unique_ptr ShellTestPlatformViewMetal::CreateRenderingSurface() { - return std::make_unique(this, [metal_context_->context() mainContext], 1); + return std::make_unique(this, [metal_context_->context() mainContext]); } // |GPUSurfaceMetalDelegate| diff --git a/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.h b/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.h index fd5c07fc27..378051ba32 100644 --- a/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.h +++ b/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.h @@ -17,7 +17,6 @@ class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetalSkia : public Surface { public: GPUSurfaceMetalSkia(GPUSurfaceMetalDelegate* delegate, sk_sp context, - int msaa_samples, bool render_to_surface = true); // |Surface| @@ -31,7 +30,6 @@ class SK_API_AVAILABLE_CA_METAL_LAYER GPUSurfaceMetalSkia : public Surface { const MTLRenderTargetType render_target_type_; sk_sp context_; GrDirectContext* precompiled_sksl_context_ = nullptr; - int msaa_samples_ = 1; // TODO(38466): Refactor GPU surface APIs take into account the fact that an // external view embedder may want to render to the root surface. This is a // hack to make avoid allocating resources for the root surface when an diff --git a/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm b/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm index e98952d8c1..e14cc98bf7 100644 --- a/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm +++ b/engine/src/flutter/shell/gpu/gpu_surface_metal_skia.mm @@ -47,18 +47,11 @@ sk_sp CreateSurfaceFromMetalTexture(GrDirectContext* context, GPUSurfaceMetalSkia::GPUSurfaceMetalSkia(GPUSurfaceMetalDelegate* delegate, sk_sp context, - int msaa_samples, bool render_to_surface) : delegate_(delegate), render_target_type_(delegate->GetRenderTargetType()), context_(std::move(context)), - msaa_samples_(msaa_samples), - render_to_surface_(render_to_surface) { - // Skia allows 0 and clamps it to 1. - FML_CHECK(msaa_samples_ == 0 || msaa_samples_ == 1 || msaa_samples_ == 2 || msaa_samples_ == 4 || - msaa_samples_ == 8) - << "Invalid MSAA sample count value: " << msaa_samples_; -} + render_to_surface_(render_to_surface) {} GPUSurfaceMetalSkia::~GPUSurfaceMetalSkia() = default; @@ -127,9 +120,20 @@ std::unique_ptr GPUSurfaceMetalSkia::AcquireFrameFromCAMetalLayer( return nullptr; } + // TODO(dnfield): Enable MSAA behind a flag if the settings say to. + // https://github.com/flutter/flutter/issues/100392 + // Rough outline of steps needed: + // Create memoryless texture + // auto texture = drawable.get().texture; + // MTLTextureDescriptor* desc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat: + // texture.pixelFormat width: texture.width height: texture.height: mipmapped: texture.mipmapped]; + // desc.sampleCount = 4; + // Type should be multisample, count 4 or 8 (4 always supported) + // Give the new texture to skia in this call, using the same sampleCount value + // Resolve texture auto surface = CreateSurfaceFromMetalTexture(context_.get(), drawable.get().texture, kTopLeft_GrSurfaceOrigin, // origin - msaa_samples_, // sample count + 1, // sample count kBGRA_8888_SkColorType, // color type nullptr, // colorspace nullptr // surface properties @@ -193,8 +197,8 @@ std::unique_ptr GPUSurfaceMetalSkia::AcquireFrameFromMTLTexture( } sk_sp surface = - CreateSurfaceFromMetalTexture(context_.get(), mtl_texture, kTopLeft_GrSurfaceOrigin, - msaa_samples_, kBGRA_8888_SkColorType, nullptr, nullptr); + CreateSurfaceFromMetalTexture(context_.get(), mtl_texture, kTopLeft_GrSurfaceOrigin, 1, + kBGRA_8888_SkColorType, nullptr, nullptr); if (!surface) { FML_LOG(ERROR) << "Could not create the SkSurface from the metal texture."; diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm index 1b08af9123..270aab3fba 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm @@ -19,7 +19,6 @@ namespace flutter { namespace { class FakeDelegate : public PlatformView::Delegate { - public: void OnPlatformViewCreated(std::unique_ptr surface) override {} void OnPlatformViewDestroyed() override {} void OnPlatformViewScheduleFrame() override {} @@ -48,6 +47,7 @@ class FakeDelegate : public PlatformView::Delegate { void UpdateAssetResolverByType(std::unique_ptr updated_asset_resolver, AssetResolver::AssetResolverType type) override {} + private: flutter::Settings settings_; }; @@ -87,29 +87,6 @@ flutter::FakeDelegate fake_delegate; return weak_factory->GetWeakPtr(); } -- (void)testMsaaSampleCount { - // Default should be 1. - XCTAssertEqual(platform_view->GetIosContext()->GetMsaaSampleCount(), 1); - - // Verify the platform view creates a new context with updated msaa_samples. - // Need to use Metal, since this is ignored for Software/GL. - fake_delegate.settings_.msaa_samples = 4; - - auto thread_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner(); - flutter::TaskRunners runners(/*label=*/self.name.UTF8String, - /*platform=*/thread_task_runner, - /*raster=*/thread_task_runner, - /*ui=*/thread_task_runner, - /*io=*/thread_task_runner); - auto msaa_4x_platform_view = std::make_unique( - /*delegate=*/fake_delegate, - /*rendering_api=*/flutter::IOSRenderingAPI::kMetal, - /*platform_views_controller=*/nil, - /*task_runners=*/runners); - - XCTAssertEqual(msaa_4x_platform_view->GetIosContext()->GetMsaaSampleCount(), 4); -} - - (void)testCallsNotifyLowMemory { id project = OCMClassMock([FlutterDartProject class]); FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"tester" project:project]; diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context.h b/engine/src/flutter/shell/platform/darwin/ios/ios_context.h index 10844c49df..8cf8fb0fb7 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context.h +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context.h @@ -21,9 +21,6 @@ class Context; namespace flutter { -// Supported MSAA sample count values for iOS. -enum class MsaaSampleCount { kNone = 1, kTwo = 2, kFour = 4, kEight = 8 }; - //------------------------------------------------------------------------------ /// @brief Manages the lifetime of the on-screen and off-screen rendering /// contexts on iOS. On-screen contexts are used by Flutter for @@ -48,17 +45,10 @@ class IOSContext { /// /// @param[in] api A client rendering API supported by the /// engine/platform. - /// @param[in] backend A client rendering backend supported by the - /// engine/platform. - /// @param[in] msaa_samples - /// The number of MSAA samples to use. Only supplied to - /// Skia, must be either 0, 1, 2, 4, or 8. /// /// @return A valid context on success. `nullptr` on failure. /// - static std::unique_ptr Create(IOSRenderingAPI api, - IOSRenderingBackend backend, - MsaaSampleCount msaa_samples); + static std::unique_ptr Create(IOSRenderingAPI api, IOSRenderingBackend backend); //---------------------------------------------------------------------------- /// @brief Collects the context object. This must happen on the thread on @@ -143,13 +133,10 @@ class IOSContext { virtual std::shared_ptr GetImpellerContext() const; - int GetMsaaSampleCount() const { return static_cast(msaa_samples_); } - protected: - explicit IOSContext(MsaaSampleCount msaa_samples); + IOSContext(); private: - MsaaSampleCount msaa_samples_ = MsaaSampleCount::kNone; FML_DISALLOW_COPY_AND_ASSIGN(IOSContext); }; 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 59b8c6fcc1..5fd6de9c94 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context.mm @@ -15,13 +15,11 @@ namespace flutter { -IOSContext::IOSContext(MsaaSampleCount msaa_samples) : msaa_samples_(msaa_samples) {} +IOSContext::IOSContext() = default; IOSContext::~IOSContext() = default; -std::unique_ptr IOSContext::Create(IOSRenderingAPI api, - IOSRenderingBackend backend, - MsaaSampleCount msaa_samples) { +std::unique_ptr IOSContext::Create(IOSRenderingAPI api, IOSRenderingBackend backend) { switch (api) { case IOSRenderingAPI::kOpenGLES: return std::make_unique(); @@ -31,7 +29,7 @@ std::unique_ptr IOSContext::Create(IOSRenderingAPI api, case IOSRenderingAPI::kMetal: switch (backend) { case IOSRenderingBackend::kSkia: - return std::make_unique(msaa_samples); + return std::make_unique(); case IOSRenderingBackend::kImpeller: return std::make_unique(); } diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context_gl.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_context_gl.mm index b92bc6d01c..d183a29150 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context_gl.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context_gl.mm @@ -13,7 +13,7 @@ namespace flutter { -IOSContextGL::IOSContextGL() : IOSContext(MsaaSampleCount::kNone) { +IOSContextGL::IOSContextGL() { resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]); if (resource_context_ != nullptr) { context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3 diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_impeller.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_impeller.mm index 1b15943255..b3b4cfdac2 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_impeller.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_impeller.mm @@ -22,8 +22,7 @@ static std::shared_ptr CreateImpellerContext() { return context; } -IOSContextMetalImpeller::IOSContextMetalImpeller() - : IOSContext(MsaaSampleCount::kFour), context_(CreateImpellerContext()) {} +IOSContextMetalImpeller::IOSContextMetalImpeller() : context_(CreateImpellerContext()) {} IOSContextMetalImpeller::~IOSContextMetalImpeller() = default; diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.h b/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.h index 9c6193c21f..9d0eac239a 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.h +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.h @@ -18,7 +18,7 @@ namespace flutter { class IOSContextMetalSkia final : public IOSContext { public: - explicit IOSContextMetalSkia(MsaaSampleCount msaa_samples); + IOSContextMetalSkia(); ~IOSContextMetalSkia(); diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm index 5476f45611..0e1d53beba 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context_metal_skia.mm @@ -12,7 +12,7 @@ namespace flutter { -IOSContextMetalSkia::IOSContextMetalSkia(MsaaSampleCount msaa_samples) : IOSContext(msaa_samples) { +IOSContextMetalSkia::IOSContextMetalSkia() { darwin_context_metal_ = fml::scoped_nsobject{ [[FlutterDarwinContextMetal alloc] initWithDefaultMTLDevice]}; diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_context_software.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_context_software.mm index c58ad6dc93..7005b50464 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_context_software.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_context_software.mm @@ -3,11 +3,10 @@ // found in the LICENSE file. #import "flutter/shell/platform/darwin/ios/ios_context_software.h" -#include "ios_context.h" namespace flutter { -IOSContextSoftware::IOSContextSoftware() : IOSContext(MsaaSampleCount::kNone) {} +IOSContextSoftware::IOSContextSoftware() = default; // |IOSContext| IOSContextSoftware::~IOSContextSoftware() = default; diff --git a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.mm b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.mm index 9a4d8b2e48..b0e76f5e10 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/ios_surface_metal_skia.mm @@ -42,9 +42,8 @@ void IOSSurfaceMetalSkia::UpdateStorageSizeIfNecessary() { // |IOSSurface| std::unique_ptr IOSSurfaceMetalSkia::CreateGPUSurface(GrDirectContext* context) { FML_DCHECK(context); - return std::make_unique(this, // delegate - sk_ref_sp(context), // context - GetContext()->GetMsaaSampleCount() // sample count + return std::make_unique(this, // layer + sk_ref_sp(context) // context ); } diff --git a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm index 61b9c3aeaa..b2f549887a 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/platform_view_ios.mm @@ -55,15 +55,13 @@ PlatformViewIOS::PlatformViewIOS( IOSRenderingAPI rendering_api, const std::shared_ptr& platform_views_controller, flutter::TaskRunners task_runners) - : PlatformViewIOS( - delegate, - IOSContext::Create( - rendering_api, - delegate.OnPlatformViewGetSettings().enable_impeller ? IOSRenderingBackend::kImpeller - : IOSRenderingBackend::kSkia, - static_cast(delegate.OnPlatformViewGetSettings().msaa_samples)), - platform_views_controller, - task_runners) {} + : PlatformViewIOS(delegate, + IOSContext::Create(rendering_api, + delegate.OnPlatformViewGetSettings().enable_impeller + ? IOSRenderingBackend::kImpeller + : IOSRenderingBackend::kSkia), + platform_views_controller, + task_runners) {} PlatformViewIOS::~PlatformViewIOS() = default; diff --git a/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.mm b/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.mm index 080f44d14e..8499cab048 100644 --- a/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.mm +++ b/engine/src/flutter/shell/platform/embedder/embedder_surface_metal.mm @@ -44,7 +44,7 @@ std::unique_ptr EmbedderSurfaceMetal::CreateGPUSurface() API_AVAILABLE( } const bool render_to_surface = !external_view_embedder_; - auto surface = std::make_unique(this, main_context_, render_to_surface, 1); + auto surface = std::make_unique(this, main_context_, render_to_surface); if (!surface->IsValid()) { return nullptr;