diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 9bc86b609f7ce..5be3cb75a183a 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -930,6 +930,24 @@ FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStan FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec_Internal.h FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_codecs_unittest.mm FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/flutter_standard_codec_unittest.mm +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_context.h +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_context.mm +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_context_gl.h +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_context_gl.mm +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_context_metal.h +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_context_metal.mm +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_context_software.h +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_context_software.mm +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_external_texture_gl.h +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_external_texture_gl.mm +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_external_texture_metal.h +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_external_texture_metal.mm +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_render_target_gl.h +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_render_target_gl.mm +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_switchable_gl_context.h +FILE: ../../../flutter/shell/platform/darwin/graphics/ios_switchable_gl_context.mm +FILE: ../../../flutter/shell/platform/darwin/graphics/rendering_api_selection.h +FILE: ../../../flutter/shell/platform/darwin/graphics/rendering_api_selection.mm FILE: ../../../flutter/shell/platform/darwin/ios/framework/Flutter.podspec FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/Flutter.h FILE: ../../../flutter/shell/platform/darwin/ios/framework/Headers/FlutterAppDelegate.h @@ -1005,38 +1023,18 @@ FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/profiler_metri FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h FILE: ../../../flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm FILE: ../../../flutter/shell/platform/darwin/ios/framework/module.modulemap -FILE: ../../../flutter/shell/platform/darwin/ios/ios_context.h -FILE: ../../../flutter/shell/platform/darwin/ios/ios_context.mm -FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_gl.h -FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_gl.mm -FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal.h -FILE: ../../../flutter/shell/platform/darwin/ios/ios_context_metal.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_gl.h -FILE: ../../../flutter/shell/platform/darwin/ios/ios_external_texture_gl.mm -FILE: ../../../flutter/shell/platform/darwin/ios/ios_external_texture_metal.h -FILE: ../../../flutter/shell/platform/darwin/ios/ios_external_texture_metal.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_external_view_embedder.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_external_view_embedder.mm -FILE: ../../../flutter/shell/platform/darwin/ios/ios_render_target_gl.h -FILE: ../../../flutter/shell/platform/darwin/ios/ios_render_target_gl.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface.mm -FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_factory.h -FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_factory.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_gl.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_gl.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_metal.mm FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_software.h FILE: ../../../flutter/shell/platform/darwin/ios/ios_surface_software.mm -FILE: ../../../flutter/shell/platform/darwin/ios/ios_switchable_gl_context.h -FILE: ../../../flutter/shell/platform/darwin/ios/ios_switchable_gl_context.mm FILE: ../../../flutter/shell/platform/darwin/ios/platform_view_ios.h FILE: ../../../flutter/shell/platform/darwin/ios/platform_view_ios.mm -FILE: ../../../flutter/shell/platform/darwin/ios/rendering_api_selection.h -FILE: ../../../flutter/shell/platform/darwin/ios/rendering_api_selection.mm FILE: ../../../flutter/shell/platform/darwin/macos/framework/FlutterMacOS.podspec FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterAppDelegate.h FILE: ../../../flutter/shell/platform/darwin/macos/framework/Headers/FlutterDartProject.h diff --git a/flow/testing/gl_context_switch_test.h b/flow/testing/gl_context_switch_test.h index e2cd8b96c0c35..a9f5479180dde 100644 --- a/flow/testing/gl_context_switch_test.h +++ b/flow/testing/gl_context_switch_test.h @@ -8,6 +8,7 @@ #include "flutter/common/graphics/gl_context_switch.h" #include "gtest/gtest.h" +// TODO (kaushik): move to /flutter/common/graphics namespace flutter { namespace testing { diff --git a/shell/common/persistent_cache_unittests.cc b/shell/common/persistent_cache_unittests.cc index 3d45c09302f76..2ca568c47515e 100644 --- a/shell/common/persistent_cache_unittests.cc +++ b/shell/common/persistent_cache_unittests.cc @@ -21,6 +21,7 @@ #include "flutter/testing/testing.h" #include "include/core/SkPicture.h" +// TODO(kaushik): move to /flutter/common/graphics namespace flutter { namespace testing { diff --git a/shell/platform/darwin/graphics/BUILD.gn b/shell/platform/darwin/graphics/BUILD.gn new file mode 100644 index 0000000000000..ad08c1f785243 --- /dev/null +++ b/shell/platform/darwin/graphics/BUILD.gn @@ -0,0 +1,65 @@ +# 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. + +assert(is_ios) + +import("//flutter/common/config.gni") +import("//flutter/shell/gpu/gpu.gni") +import("//flutter/shell/platform/darwin/common/framework_shared.gni") + +shell_gpu_configuration("ios_gpu_configuration") { + enable_software = true + enable_gl = true + enable_vulkan = false + enable_metal = shell_enable_metal +} + +source_set("flutter_ios_graphics") { + cflags_objc = flutter_cflags_objc + cflags_objcc = flutter_cflags_objcc + defines = [] + + sources = [ + "ios_context.h", + "ios_context.mm", + "ios_context_gl.h", + "ios_context_gl.mm", + "ios_context_software.h", + "ios_context_software.mm", + "ios_external_texture_gl.h", + "ios_external_texture_gl.mm", + "ios_render_target_gl.h", + "ios_render_target_gl.mm", + "ios_switchable_gl_context.h", + "ios_switchable_gl_context.mm", + "rendering_api_selection.h", + "rendering_api_selection.mm", + ] + + if (shell_enable_metal) { + defines += [ "FLUTTER_SHELL_ENABLE_METAL=1" ] + + sources += [ + "ios_context_metal.h", + "ios_context_metal.mm", + "ios_external_texture_metal.h", + "ios_external_texture_metal.mm", + ] + } + + deps = [ + ":ios_gpu_configuration", + "//flutter/fml", + "//flutter/common/graphics", + "//flutter/shell/platform/darwin/common:framework_shared", + "//third_party/skia", + ] + + libs = [ + "CoreMedia.framework", + "CoreVideo.framework", + "OpenGLES.framework", + "QuartzCore.framework", + ] +} diff --git a/shell/platform/darwin/ios/ios_context.h b/shell/platform/darwin/graphics/ios_context.h similarity index 91% rename from shell/platform/darwin/ios/ios_context.h rename to shell/platform/darwin/graphics/ios_context.h index 6b2bf5e766c5b..aaa67d20392c3 100644 --- a/shell/platform/darwin/ios/ios_context.h +++ b/shell/platform/darwin/graphics/ios_context.h @@ -2,17 +2,15 @@ // 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_RESOURCE_CONTEXT_H_ -#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_RESOURCE_CONTEXT_H_ +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_RESOURCE_CONTEXT_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_RESOURCE_CONTEXT_H_ #include -#include "flutter/common/graphics/gl_context_switch.h" -#include "flutter/common/graphics/texture.h" #include "flutter/fml/macros.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h" -#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" +#import "flutter/shell/platform/darwin/graphics/rendering_api_selection.h" #include "third_party/skia/include/gpu/GrDirectContext.h" namespace flutter { @@ -90,7 +88,7 @@ class IOSContext { /// bound to the current /// thread. /// - virtual std::unique_ptr MakeCurrent() = 0; + virtual std::unique_ptr MakeCurrent() const = 0; //---------------------------------------------------------------------------- /// @brief Creates an external texture proxy of the appropriate client @@ -115,4 +113,4 @@ class IOSContext { } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_RESOURCE_CONTEXT_H_ +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_RESOURCE_CONTEXT_H_ diff --git a/shell/platform/darwin/ios/ios_context.mm b/shell/platform/darwin/graphics/ios_context.mm similarity index 76% rename from shell/platform/darwin/ios/ios_context.mm rename to shell/platform/darwin/graphics/ios_context.mm index 0472ba6fc8d17..8473ac5f98d55 100644 --- a/shell/platform/darwin/ios/ios_context.mm +++ b/shell/platform/darwin/graphics/ios_context.mm @@ -2,14 +2,14 @@ // 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.h" +#import "flutter/shell/platform/darwin/graphics/ios_context.h" #include "flutter/fml/logging.h" -#import "flutter/shell/platform/darwin/ios/ios_context_gl.h" -#import "flutter/shell/platform/darwin/ios/ios_context_software.h" +#import "flutter/shell/platform/darwin/graphics/ios_context_gl.h" +#import "flutter/shell/platform/darwin/graphics/ios_context_software.h" #if FLUTTER_SHELL_ENABLE_METAL -#import "flutter/shell/platform/darwin/ios/ios_context_metal.h" +#import "flutter/shell/platform/darwin/graphics/ios_context_metal.h" #endif // FLUTTER_SHELL_ENABLE_METAL namespace flutter { diff --git a/shell/platform/darwin/ios/ios_context_gl.h b/shell/platform/darwin/graphics/ios_context_gl.h similarity index 60% rename from shell/platform/darwin/ios/ios_context_gl.h rename to shell/platform/darwin/graphics/ios_context_gl.h index 69260e1903efa..ce559700da133 100644 --- a/shell/platform/darwin/ios/ios_context_gl.h +++ b/shell/platform/darwin/graphics/ios_context_gl.h @@ -2,15 +2,14 @@ // 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_GL_CONTEXT_H_ -#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_GL_CONTEXT_H_ +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_GL_CONTEXT_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_GL_CONTEXT_H_ #include "flutter/fml/macros.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" -#include "flutter/shell/common/platform_view.h" -#import "flutter/shell/platform/darwin/ios/ios_context.h" -#import "flutter/shell/platform/darwin/ios/ios_context_gl.h" -#import "flutter/shell/platform/darwin/ios/ios_render_target_gl.h" +#import "flutter/shell/platform/darwin/graphics/ios_context.h" +#import "flutter/shell/platform/darwin/graphics/ios_context_gl.h" +#import "flutter/shell/platform/darwin/graphics/ios_render_target_gl.h" @class CAEAGLLayer; @@ -23,7 +22,8 @@ class IOSContextGL final : public IOSContext { // |IOSContext| ~IOSContextGL() override; - std::unique_ptr CreateRenderTarget(fml::scoped_nsobject layer); + std::unique_ptr CreateRenderTarget( + fml::scoped_nsobject layer) const; private: fml::scoped_nsobject context_; @@ -33,7 +33,7 @@ class IOSContextGL final : public IOSContext { sk_sp CreateResourceContext() override; // |IOSContext| - std::unique_ptr MakeCurrent() override; + std::unique_ptr MakeCurrent() const override; // |IOSContext| std::unique_ptr CreateExternalTexture( @@ -45,4 +45,4 @@ class IOSContextGL final : public IOSContext { } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_GL_CONTEXT_H_ +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_GL_CONTEXT_H_ diff --git a/shell/platform/darwin/ios/ios_context_gl.mm b/shell/platform/darwin/graphics/ios_context_gl.mm similarity index 50% rename from shell/platform/darwin/ios/ios_context_gl.mm rename to shell/platform/darwin/graphics/ios_context_gl.mm index 4de8f11935ffa..8014ce0b32c94 100644 --- a/shell/platform/darwin/ios/ios_context_gl.mm +++ b/shell/platform/darwin/graphics/ios_context_gl.mm @@ -2,16 +2,48 @@ // 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_gl.h" +#import "flutter/shell/platform/darwin/graphics/ios_context_gl.h" #import -#include "flutter/shell/common/shell_io_manager.h" +#include "flutter/common/graphics/persistent_cache.h" #include "flutter/shell/gpu/gpu_surface_gl_delegate.h" -#import "flutter/shell/platform/darwin/ios/ios_external_texture_gl.h" +#import "flutter/shell/platform/darwin/graphics/ios_external_texture_gl.h" namespace flutter { +static sk_sp CreateCompatibleResourceLoadingContext( + sk_sp gl_interface) { + GrContextOptions options = {}; + if (PersistentCache::cache_sksl()) { + FML_LOG(INFO) << "Cache SkSL"; + options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL; + } + PersistentCache::MarkStrategySet(); + + options.fPersistentCache = PersistentCache::GetCacheForProcess(); + + // There is currently a bug with doing GPU YUV to RGB conversions on the IO + // thread. The necessary work isn't being flushed or synchronized with the + // other threads correctly, so the textures end up blank. For now, suppress + // that feature, which will cause texture uploads to do CPU YUV conversion. + // A similar work-around is also used in shell/gpu/gpu_surface_gl.cc. + options.fDisableGpuYUVConversion = true; + + // To get video playback on the widest range of devices, we limit Skia to + // ES2 shading language when the ES3 external image extension is missing. + options.fPreferExternalImagesOverES3 = true; + + if (auto context = GrDirectContext::MakeGL(gl_interface, options)) { + // Do not cache textures created by the image decoder. These textures + // should be deleted when they are no longer referenced by an SkImage. + context->setResourceCacheLimits(0, 0); + return context; + } + + return nullptr; +} + IOSContextGL::IOSContextGL() { resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]); if (resource_context_ != nullptr) { @@ -27,7 +59,7 @@ IOSContextGL::~IOSContextGL() = default; std::unique_ptr IOSContextGL::CreateRenderTarget( - fml::scoped_nsobject layer) { + fml::scoped_nsobject layer) const { return std::make_unique(std::move(layer), context_); } @@ -39,12 +71,12 @@ return nullptr; } - return ShellIOManager::CreateCompatibleResourceLoadingContext( - GrBackend::kOpenGL_GrBackend, GPUSurfaceGLDelegate::GetDefaultPlatformGLInterface()); + return CreateCompatibleResourceLoadingContext( + GPUSurfaceGLDelegate::GetDefaultPlatformGLInterface()); } // |IOSContext| -std::unique_ptr IOSContextGL::MakeCurrent() { +std::unique_ptr IOSContextGL::MakeCurrent() const { return std::make_unique( std::make_unique(context_.get())); } diff --git a/shell/platform/darwin/ios/ios_context_metal.h b/shell/platform/darwin/graphics/ios_context_metal.h similarity index 81% rename from shell/platform/darwin/ios/ios_context_metal.h rename to shell/platform/darwin/graphics/ios_context_metal.h index f1928528ac390..f0172c0bbfb69 100644 --- a/shell/platform/darwin/ios/ios_context_metal.h +++ b/shell/platform/darwin/graphics/ios_context_metal.h @@ -2,15 +2,15 @@ // 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_METAL_H_ -#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_H_ +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_CONTEXT_METAL_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_CONTEXT_METAL_H_ #include #include "flutter/fml/macros.h" #include "flutter/fml/platform/darwin/cf_utils.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" -#import "flutter/shell/platform/darwin/ios/ios_context.h" +#import "flutter/shell/platform/darwin/graphics/ios_context.h" #include "third_party/skia/include/gpu/GrDirectContext.h" namespace flutter { @@ -42,7 +42,7 @@ class IOSContextMetal final : public IOSContext { sk_sp CreateResourceContext() override; // |IOSContext| - std::unique_ptr MakeCurrent() override; + std::unique_ptr MakeCurrent() const override; // |IOSContext| std::unique_ptr CreateExternalTexture( @@ -54,4 +54,4 @@ class IOSContextMetal final : public IOSContext { } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_METAL_H_ +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_CONTEXT_METAL_H_ diff --git a/shell/platform/darwin/ios/ios_context_metal.mm b/shell/platform/darwin/graphics/ios_context_metal.mm similarity index 95% rename from shell/platform/darwin/ios/ios_context_metal.mm rename to shell/platform/darwin/graphics/ios_context_metal.mm index 21a7f7e66f1ad..56c831313c73a 100644 --- a/shell/platform/darwin/ios/ios_context_metal.mm +++ b/shell/platform/darwin/graphics/ios_context_metal.mm @@ -2,11 +2,11 @@ // 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_metal.h" +#import "flutter/shell/platform/darwin/graphics/ios_context_metal.h" #include "flutter/common/graphics/persistent_cache.h" #include "flutter/fml/logging.h" -#import "flutter/shell/platform/darwin/ios/ios_external_texture_metal.h" +#import "flutter/shell/platform/darwin/graphics/ios_external_texture_metal.h" #include "third_party/skia/include/gpu/GrContextOptions.h" namespace flutter { @@ -96,7 +96,7 @@ static GrContextOptions CreateMetalGrContextOptions() { } // |IOSContext| -std::unique_ptr IOSContextMetal::MakeCurrent() { +std::unique_ptr IOSContextMetal::MakeCurrent() const { // This only makes sense for context that need to be bound to a specific thread. return std::make_unique(true); } diff --git a/shell/platform/darwin/ios/ios_context_software.h b/shell/platform/darwin/graphics/ios_context_software.h similarity index 67% rename from shell/platform/darwin/ios/ios_context_software.h rename to shell/platform/darwin/graphics/ios_context_software.h index 4407be6033cc7..711fc7477b749 100644 --- a/shell/platform/darwin/ios/ios_context_software.h +++ b/shell/platform/darwin/graphics/ios_context_software.h @@ -2,11 +2,11 @@ // 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_SOFTWARE_H_ -#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_SOFTWARE_H_ +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_CONTEXT_SOFTWARE_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_CONTEXT_SOFTWARE_H_ #include "flutter/fml/macros.h" -#import "flutter/shell/platform/darwin/ios/ios_context.h" +#import "flutter/shell/platform/darwin/graphics/ios_context.h" namespace flutter { @@ -21,7 +21,7 @@ class IOSContextSoftware final : public IOSContext { sk_sp CreateResourceContext() override; // |IOSContext| - std::unique_ptr MakeCurrent() override; + std::unique_ptr MakeCurrent() const override; // |IOSContext| std::unique_ptr CreateExternalTexture( @@ -34,4 +34,4 @@ class IOSContextSoftware final : public IOSContext { } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_CONTEXT_SOFTWARE_H_ +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_CONTEXT_SOFTWARE_H_ diff --git a/shell/platform/darwin/ios/ios_context_software.mm b/shell/platform/darwin/graphics/ios_context_software.mm similarity index 93% rename from shell/platform/darwin/ios/ios_context_software.mm rename to shell/platform/darwin/graphics/ios_context_software.mm index 261fdc44a450a..b1ca1f30d2c1d 100644 --- a/shell/platform/darwin/ios/ios_context_software.mm +++ b/shell/platform/darwin/graphics/ios_context_software.mm @@ -2,7 +2,7 @@ // 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_software.h" +#import "flutter/shell/platform/darwin/graphics/ios_context_software.h" namespace flutter { @@ -17,7 +17,7 @@ } // |IOSContext| -std::unique_ptr IOSContextSoftware::MakeCurrent() { +std::unique_ptr IOSContextSoftware::MakeCurrent() const { // This only makes sense for context that need to be bound to a specific thread. return std::make_unique(false); } diff --git a/shell/platform/darwin/ios/ios_external_texture_gl.h b/shell/platform/darwin/graphics/ios_external_texture_gl.h similarity index 100% rename from shell/platform/darwin/ios/ios_external_texture_gl.h rename to shell/platform/darwin/graphics/ios_external_texture_gl.h diff --git a/shell/platform/darwin/ios/ios_external_texture_gl.mm b/shell/platform/darwin/graphics/ios_external_texture_gl.mm similarity index 98% rename from shell/platform/darwin/ios/ios_external_texture_gl.mm rename to shell/platform/darwin/graphics/ios_external_texture_gl.mm index 1429add5f283e..175ca672a6e8c 100644 --- a/shell/platform/darwin/ios/ios_external_texture_gl.mm +++ b/shell/platform/darwin/graphics/ios_external_texture_gl.mm @@ -2,13 +2,13 @@ // 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_external_texture_gl.h" +#import "flutter/shell/platform/darwin/graphics/ios_external_texture_gl.h" #import #import #import -#import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h" +#include "flutter/fml/logging.h" #include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkYUVAIndex.h" #include "third_party/skia/include/gpu/GrBackendSurface.h" diff --git a/shell/platform/darwin/ios/ios_external_texture_metal.h b/shell/platform/darwin/graphics/ios_external_texture_metal.h similarity index 90% rename from shell/platform/darwin/ios/ios_external_texture_metal.h rename to shell/platform/darwin/graphics/ios_external_texture_metal.h index dcd8a48170ad7..1b23c145eb0d1 100644 --- a/shell/platform/darwin/ios/ios_external_texture_metal.h +++ b/shell/platform/darwin/graphics/ios_external_texture_metal.h @@ -2,8 +2,8 @@ // 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_EXTERNAL_TEXTURE_METAL_H_ -#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_EXTERNAL_TEXTURE_METAL_H_ +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_EXTERNAL_TEXTURE_METAL_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_EXTERNAL_TEXTURE_METAL_H_ #include @@ -66,4 +66,4 @@ class IOSExternalTextureMetal final : public Texture { } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_EXTERNAL_TEXTURE_METAL_H_ +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_EXTERNAL_TEXTURE_METAL_H_ diff --git a/shell/platform/darwin/ios/ios_external_texture_metal.mm b/shell/platform/darwin/graphics/ios_external_texture_metal.mm similarity index 99% rename from shell/platform/darwin/ios/ios_external_texture_metal.mm rename to shell/platform/darwin/graphics/ios_external_texture_metal.mm index 859022bc0e381..077b51bfb3c52 100644 --- a/shell/platform/darwin/ios/ios_external_texture_metal.mm +++ b/shell/platform/darwin/graphics/ios_external_texture_metal.mm @@ -2,7 +2,7 @@ // 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_external_texture_metal.h" +#import "flutter/shell/platform/darwin/graphics/ios_external_texture_metal.h" #include "flutter/fml/logging.h" #include "third_party/skia/include/core/SkYUVAIndex.h" diff --git a/shell/platform/darwin/ios/ios_render_target_gl.h b/shell/platform/darwin/graphics/ios_render_target_gl.h similarity index 76% rename from shell/platform/darwin/ios/ios_render_target_gl.h rename to shell/platform/darwin/graphics/ios_render_target_gl.h index f2c972f948bbe..6ab36479fc09a 100644 --- a/shell/platform/darwin/ios/ios_render_target_gl.h +++ b/shell/platform/darwin/graphics/ios_render_target_gl.h @@ -2,8 +2,8 @@ // 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_RENDER_TARGET_GL_H_ -#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_RENDER_TARGET_GL_H_ +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_RENDER_TARGET_GL_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_RENDER_TARGET_GL_H_ #import #import @@ -12,8 +12,7 @@ #include "flutter/fml/macros.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" -#include "flutter/shell/common/platform_view.h" -#import "flutter/shell/platform/darwin/ios/ios_switchable_gl_context.h" +#import "flutter/shell/platform/darwin/graphics/ios_switchable_gl_context.h" namespace flutter { @@ -46,4 +45,4 @@ class IOSRenderTargetGL { } // namespace flutter -#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_RENDER_TARGET_GL_H_ +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_RENDER_TARGET_GL_H_ diff --git a/shell/platform/darwin/ios/ios_render_target_gl.mm b/shell/platform/darwin/graphics/ios_render_target_gl.mm similarity index 98% rename from shell/platform/darwin/ios/ios_render_target_gl.mm rename to shell/platform/darwin/graphics/ios_render_target_gl.mm index 28fb24263b262..c36d767f3e5d4 100644 --- a/shell/platform/darwin/ios/ios_render_target_gl.mm +++ b/shell/platform/darwin/graphics/ios_render_target_gl.mm @@ -2,7 +2,7 @@ // 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_render_target_gl.h" +#import "flutter/shell/platform/darwin/graphics/ios_render_target_gl.h" #include diff --git a/shell/platform/darwin/ios/ios_switchable_gl_context.h b/shell/platform/darwin/graphics/ios_switchable_gl_context.h similarity index 91% rename from shell/platform/darwin/ios/ios_switchable_gl_context.h rename to shell/platform/darwin/graphics/ios_switchable_gl_context.h index 24bceb3e60249..09d0adf3666ac 100644 --- a/shell/platform/darwin/ios/ios_switchable_gl_context.h +++ b/shell/platform/darwin/graphics/ios_switchable_gl_context.h @@ -2,8 +2,8 @@ // 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_SWITCHABLE_GL_CONTEXT_H_ -#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SWITCHABLE_GL_CONTEXT_H_ +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_SWITCHABLE_GL_CONTEXT_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_IOS_SWITCHABLE_GL_CONTEXT_H_ #include "flutter/common/graphics/gl_context_switch.h" #include "flutter/fml/macros.h" diff --git a/shell/platform/darwin/ios/ios_switchable_gl_context.mm b/shell/platform/darwin/graphics/ios_switchable_gl_context.mm similarity index 90% rename from shell/platform/darwin/ios/ios_switchable_gl_context.mm rename to shell/platform/darwin/graphics/ios_switchable_gl_context.mm index 895ce2128e703..de17ffc03f5f0 100644 --- a/shell/platform/darwin/ios/ios_switchable_gl_context.mm +++ b/shell/platform/darwin/graphics/ios_switchable_gl_context.mm @@ -2,7 +2,7 @@ // 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_switchable_gl_context.h" +#import "flutter/shell/platform/darwin/graphics/ios_switchable_gl_context.h" #import diff --git a/shell/platform/darwin/ios/rendering_api_selection.h b/shell/platform/darwin/graphics/rendering_api_selection.h similarity index 82% rename from shell/platform/darwin/ios/rendering_api_selection.h rename to shell/platform/darwin/graphics/rendering_api_selection.h index 07fe13ccb198d..13c26e41f0f5a 100644 --- a/shell/platform/darwin/ios/rendering_api_selection.h +++ b/shell/platform/darwin/graphics/rendering_api_selection.h @@ -2,8 +2,8 @@ // 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_RENDERING_API_SELECTION_H_ -#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_RENDERING_API_SELECTION_H_ +#ifndef FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_RENDERING_API_SELECTION_H_ +#define FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_RENDERING_API_SELECTION_H_ #include @@ -36,4 +36,4 @@ Class GetCoreAnimationLayerClassForRenderingAPI(IOSRenderingAPI rendering_api); #define METAL_IOS_VERSION_BASELINE 10.0 #endif // TARGET_OS_SIMULATOR -#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_RENDERING_API_SELECTION_H_ +#endif // FLUTTER_SHELL_PLATFORM_DARWIN_GRAPHICS_RENDERING_API_SELECTION_H_ diff --git a/shell/platform/darwin/ios/rendering_api_selection.mm b/shell/platform/darwin/graphics/rendering_api_selection.mm similarity index 96% rename from shell/platform/darwin/ios/rendering_api_selection.mm rename to shell/platform/darwin/graphics/rendering_api_selection.mm index 2cf23bcccd6d5..1d992c7e628ab 100644 --- a/shell/platform/darwin/ios/rendering_api_selection.mm +++ b/shell/platform/darwin/graphics/rendering_api_selection.mm @@ -2,7 +2,7 @@ // 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/rendering_api_selection.h" +#import "flutter/shell/platform/darwin/graphics/rendering_api_selection.h" #include #include diff --git a/shell/platform/darwin/ios/BUILD.gn b/shell/platform/darwin/ios/BUILD.gn index 1090d41173144..6029c5ce78f2e 100644 --- a/shell/platform/darwin/ios/BUILD.gn +++ b/shell/platform/darwin/ios/BUILD.gn @@ -85,51 +85,22 @@ source_set("flutter_framework_source") { "framework/Source/profiler_metrics_ios.mm", "framework/Source/vsync_waiter_ios.h", "framework/Source/vsync_waiter_ios.mm", - "ios_context.h", - "ios_context.mm", - "ios_context_gl.h", - "ios_context_gl.mm", - "ios_context_software.h", - "ios_context_software.mm", - "ios_external_texture_gl.h", - "ios_external_texture_gl.mm", "ios_external_view_embedder.h", "ios_external_view_embedder.mm", - "ios_render_target_gl.h", - "ios_render_target_gl.mm", "ios_surface.h", "ios_surface.mm", - "ios_surface_factory.h", - "ios_surface_factory.mm", "ios_surface_gl.h", "ios_surface_gl.mm", "ios_surface_software.h", "ios_surface_software.mm", - "ios_switchable_gl_context.h", - "ios_switchable_gl_context.mm", "platform_view_ios.h", "platform_view_ios.mm", - "rendering_api_selection.h", - "rendering_api_selection.mm", ] sources += _flutter_framework_headers defines = [ "FLUTTER_FRAMEWORK=1" ] - if (shell_enable_metal) { - defines += [ "FLUTTER_SHELL_ENABLE_METAL=1" ] - - sources += [ - "ios_context_metal.h", - "ios_context_metal.mm", - "ios_external_texture_metal.h", - "ios_external_texture_metal.mm", - "ios_surface_metal.h", - "ios_surface_metal.mm", - ] - } - deps = [ ":ios_gpu_configuration", "//flutter/common", @@ -142,6 +113,7 @@ source_set("flutter_framework_source") { "//flutter/shell/common", "//flutter/shell/platform/darwin/common", "//flutter/shell/platform/darwin/common:framework_shared", + "//flutter/shell/platform/darwin/graphics:flutter_ios_graphics", "//flutter/shell/profiling:profiling", "//third_party/skia", ] @@ -150,10 +122,6 @@ source_set("flutter_framework_source") { libs = [ "AudioToolbox.framework", - "CoreMedia.framework", - "CoreVideo.framework", - "OpenGLES.framework", - "QuartzCore.framework", "UIKit.framework", ] if (flutter_runtime_mode == "profile" || flutter_runtime_mode == "debug") { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 9c26b05081ccc..e67bbd7356f89 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -18,6 +18,8 @@ #include "flutter/shell/common/switches.h" #include "flutter/shell/common/thread_host.h" #import "flutter/shell/platform/darwin/common/command_line.h" +#import "flutter/shell/platform/darwin/graphics/ios_context.h" +#import "flutter/shell/platform/darwin/graphics/rendering_api_selection.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.h" @@ -28,11 +30,7 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_response_darwin.h" #import "flutter/shell/platform/darwin/ios/framework/Source/profiler_metrics_ios.h" #import "flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.h" -#import "flutter/shell/platform/darwin/ios/ios_context.h" -#import "flutter/shell/platform/darwin/ios/ios_surface.h" -#import "flutter/shell/platform/darwin/ios/ios_surface_factory.h" #import "flutter/shell/platform/darwin/ios/platform_view_ios.h" -#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" #include "flutter/shell/profiling/sampling_profiler.h" NSString* const FlutterDefaultDartEntrypoint = nil; @@ -67,7 +65,6 @@ @implementation FlutterEngine { std::shared_ptr _platformViewsController; flutter::IOSRenderingAPI _renderingApi; - std::shared_ptr _surfaceFactory; std::unique_ptr _profiler_metrics; std::unique_ptr _profiler; @@ -168,9 +165,7 @@ - (instancetype)initWithName:(NSString*)labelPrefix - (void)recreatePlatformViewController { _renderingApi = flutter::GetRenderingAPIForProcess(FlutterView.forceSoftwareRendering); - _surfaceFactory = flutter::IOSSurfaceFactory::Create(_renderingApi); - _platformViewsController.reset(new flutter::FlutterPlatformViewsController(_surfaceFactory)); - _surfaceFactory->SetPlatformViewsController(_platformViewsController); + _platformViewsController.reset(new flutter::FlutterPlatformViewsController()); } - (flutter::IOSRenderingAPI)platformViewsRenderingAPI { @@ -564,7 +559,7 @@ - (BOOL)createShell:(NSString*)entrypoint [self](flutter::Shell& shell) { [self recreatePlatformViewController]; return std::make_unique( - shell, self->_renderingApi, self->_surfaceFactory, shell.GetTaskRunners()); + shell, self->_renderingApi, self->_platformViewsController, shell.GetTaskRunners()); }; flutter::Shell::CreateCallback on_create_rasterizer = diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm index 7f081b9c587a7..125551a841c42 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEnginePlatformViewTest.mm @@ -61,7 +61,7 @@ - (void)testCallsNotifyLowMemory { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id project = OCMClassMock([FlutterDartProject class]); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h b/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h index 50db832916ea4..06326cc792474 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h @@ -2,8 +2,8 @@ // 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/graphics/rendering_api_selection.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h" -#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" @class FlutterBinaryMessengerRelay; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h index b77ac7181853f..9d54f861a9cdf 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h @@ -11,7 +11,7 @@ #include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/shell.h" -#import "flutter/shell/platform/darwin/ios/ios_context_gl.h" +#import "flutter/shell/platform/darwin/graphics/ios_context_gl.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" #import "flutter/shell/platform/darwin/ios/ios_surface_gl.h" diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 6160839627ee3..249a19831ee37 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -16,14 +16,13 @@ #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" -#import "flutter/shell/platform/darwin/ios/ios_surface_factory.h" #import "flutter/shell/platform/darwin/ios/ios_surface_gl.h" namespace flutter { std::shared_ptr FlutterPlatformViewLayerPool::GetLayer( GrDirectContext* gr_context, - std::shared_ptr ios_context) { + const IOSContext& ios_context) { if (available_layer_index_ >= layers_.size()) { std::shared_ptr layer; fml::scoped_nsobject overlay_view; @@ -34,7 +33,7 @@ overlay_view_wrapper.reset([[FlutterOverlayView alloc] init]); auto ca_layer = fml::scoped_nsobject{[[overlay_view.get() layer] retain]}; - std::unique_ptr ios_surface = ios_surface_factory_->CreateSurface(ca_layer); + std::unique_ptr ios_surface = IOSSurface::Create(ios_context, ca_layer); std::unique_ptr surface = ios_surface->CreateGPUSurface(); layer = std::make_shared( @@ -46,7 +45,7 @@ overlay_view_wrapper.reset([[FlutterOverlayView alloc] initWithContentsScale:screenScale]); auto ca_layer = fml::scoped_nsobject{[[overlay_view.get() layer] retain]}; - std::unique_ptr ios_surface = ios_surface_factory_->CreateSurface(ca_layer); + std::unique_ptr ios_surface = IOSSurface::Create(ios_context, ca_layer); std::unique_ptr surface = ios_surface->CreateGPUSurface(gr_context); layer = std::make_shared( @@ -464,7 +463,7 @@ } bool FlutterPlatformViewsController::SubmitFrame(GrDirectContext* gr_context, - std::shared_ptr ios_context, + const IOSContext& ios_context, std::unique_ptr frame) { // Any UIKit related code has to run on main thread. FML_DCHECK([[NSThread currentThread] isMainThread]); @@ -600,7 +599,7 @@ std::shared_ptr FlutterPlatformViewsController::GetLayer( GrDirectContext* gr_context, - std::shared_ptr ios_context, + const IOSContext& ios_context, sk_sp picture, SkRect rect, int64_t view_id, diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm index 6ba832b78b945..ade365df73655 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsTest.mm @@ -115,17 +115,13 @@ - (void)testCanCreatePlatformViewWithoutFlutterView { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); + auto flutterPlatformViewsController = std::make_shared(); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*ios_surface_factory=*/surface_factory, + /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - auto flutterPlatformViewsController = - std::make_shared(surface_factory); - surface_factory->SetPlatformViewsController(flutterPlatformViewsController); - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; flutterPlatformViewsController->RegisterViewFactory( @@ -173,17 +169,13 @@ - (void)testCompositePlatformView { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); + auto flutterPlatformViewsController = std::make_shared(); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*ios_surface_factory=*/surface_factory, + /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - auto flutterPlatformViewsController = - std::make_shared(surface_factory); - surface_factory->SetPlatformViewsController(flutterPlatformViewsController); - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; flutterPlatformViewsController->RegisterViewFactory( @@ -232,17 +224,13 @@ - (void)testChildClippingViewShouldBeTheBoundingRectOfPlatformView { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); + auto flutterPlatformViewsController = std::make_shared(); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*ios_surface_factory=*/surface_factory, + /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - auto flutterPlatformViewsController = - std::make_shared(surface_factory); - surface_factory->SetPlatformViewsController(flutterPlatformViewsController); - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; flutterPlatformViewsController->RegisterViewFactory( @@ -307,17 +295,13 @@ - (void)testClipRect { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); + auto flutterPlatformViewsController = std::make_shared(); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*ios_surface_factory=*/surface_factory, + /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - auto flutterPlatformViewsController = - std::make_shared(surface_factory); - surface_factory->SetPlatformViewsController(flutterPlatformViewsController); - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; flutterPlatformViewsController->RegisterViewFactory( @@ -383,17 +367,13 @@ - (void)testClipRRect { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); + auto flutterPlatformViewsController = std::make_shared(); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*ios_surface_factory=*/surface_factory, + /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - auto flutterPlatformViewsController = - std::make_shared(surface_factory); - surface_factory->SetPlatformViewsController(flutterPlatformViewsController); - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; flutterPlatformViewsController->RegisterViewFactory( @@ -459,17 +439,13 @@ - (void)testClipPath { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); + auto flutterPlatformViewsController = std::make_shared(); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*ios_surface_factory=*/surface_factory, + /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - auto flutterPlatformViewsController = - std::make_shared(surface_factory); - surface_factory->SetPlatformViewsController(flutterPlatformViewsController); - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; flutterPlatformViewsController->RegisterViewFactory( @@ -536,17 +512,13 @@ - (void)testSetFlutterViewControllerAfterCreateCanStillDispatchTouchEvents { /*raster=*/thread_task_runner, /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto surface_factory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); + auto flutterPlatformViewsController = std::make_shared(); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*ios_surface_factory=*/surface_factory, + /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); - auto flutterPlatformViewsController = - std::make_shared(surface_factory); - surface_factory->SetPlatformViewsController(flutterPlatformViewsController); - FlutterPlatformViewsTestMockFlutterPlatformFactory* factory = [[FlutterPlatformViewsTestMockFlutterPlatformFactory new] autorelease]; flutterPlatformViewsController->RegisterViewFactory( diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 299e089e0a8fc..e4a87d0c0fe0a 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -11,9 +11,9 @@ #include "flutter/shell/common/shell.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h" +#import "flutter/shell/platform/darwin/graphics/ios_context.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlatformViews.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h" -#import "flutter/shell/platform/darwin/ios/ios_context.h" #include "third_party/skia/include/core/SkPictureRecorder.h" @class FlutterTouchInterceptingView; @@ -61,7 +61,6 @@ void ResetAnchor(CALayer* layer); class IOSContextGL; class IOSSurface; -class IOSSurfaceFactory; struct FlutterPlatformViewLayer { FlutterPlatformViewLayer(fml::scoped_nsobject overlay_view, @@ -88,15 +87,14 @@ struct FlutterPlatformViewLayer { // This class isn't thread safe. class FlutterPlatformViewLayerPool { public: - FlutterPlatformViewLayerPool(std::shared_ptr ios_surface_factory) - : ios_surface_factory_(ios_surface_factory) {} + FlutterPlatformViewLayerPool() = default; ~FlutterPlatformViewLayerPool() = default; // Gets a layer from the pool if available, or allocates a new one. // Finally, it marks the layer as used. That is, it increments `available_layer_index_`. std::shared_ptr GetLayer(GrDirectContext* gr_context, - std::shared_ptr ios_context); + const IOSContext& ios_context); // Gets the layers in the pool that aren't currently used. // This method doesn't mark the layers as unused. @@ -121,14 +119,12 @@ class FlutterPlatformViewLayerPool { size_t available_layer_index_ = 0; std::vector> layers_; - const std::shared_ptr ios_surface_factory_; - FML_DISALLOW_COPY_AND_ASSIGN(FlutterPlatformViewLayerPool); }; class FlutterPlatformViewsController { public: - FlutterPlatformViewsController(std::shared_ptr surface_factory); + FlutterPlatformViewsController(); ~FlutterPlatformViewsController(); @@ -175,7 +171,7 @@ class FlutterPlatformViewsController { void Reset(); bool SubmitFrame(GrDirectContext* gr_context, - std::shared_ptr ios_context, + const IOSContext& ios_context, std::unique_ptr frame); // Invoked at the very end of a frame. @@ -289,7 +285,7 @@ class FlutterPlatformViewsController { // Allocates a new FlutterPlatformViewLayer if needed, draws the pixels within the rect from // the picture on the layer's canvas. std::shared_ptr GetLayer(GrDirectContext* gr_context, - std::shared_ptr ios_context, + const IOSContext& ios_context, sk_sp picture, SkRect rect, int64_t view_id, diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm index a46684ccb1064..a6d3d03653b17 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.mm @@ -23,9 +23,8 @@ FlutterPlatformViewLayer::~FlutterPlatformViewLayer() = default; -FlutterPlatformViewsController::FlutterPlatformViewsController( - std::shared_ptr surface_factory) - : layer_pool_(std::make_unique(surface_factory)), +FlutterPlatformViewsController::FlutterPlatformViewsController() + : layer_pool_(std::make_unique()), weak_factory_(std::make_unique>(this)){}; FlutterPlatformViewsController::~FlutterPlatformViewsController() = default; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.h b/shell/platform/darwin/ios/framework/Source/FlutterView.h index 0cdd56d2cfbdc..1d0fd92eb5919 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.h @@ -11,8 +11,8 @@ #include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/shell.h" +#import "flutter/shell/platform/darwin/graphics/ios_context.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" -#import "flutter/shell/platform/darwin/ios/ios_context.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" @protocol FlutterViewEngineDelegate diff --git a/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm b/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm index 9edb7f08324fd..fbb2404b7a3e2 100644 --- a/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm +++ b/shell/platform/darwin/ios/framework/Source/accessibility_bridge_test.mm @@ -131,7 +131,7 @@ - (void)testCreate { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); auto bridge = std::make_unique(/*view=*/nil, @@ -151,7 +151,7 @@ - (void)testUpdateSemanticsEmpty { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -178,7 +178,7 @@ - (void)testUpdateSemanticsOneNode { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -222,21 +222,18 @@ - (void)testSemanticsDeallocated { /*ui=*/thread_task_runner, /*io=*/thread_task_runner); - auto surfaceFactory = flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware); + auto flutterPlatformViewsController = + std::make_shared(); auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - /*ios_surface_factory=*/surfaceFactory, + /*platform_views_controller=*/flutterPlatformViewsController, /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); OCMStub([mockFlutterViewController view]).andReturn(mockFlutterView); std::string label = "some label"; - - auto flutterPlatformViewsController = - std::make_shared(surfaceFactory); flutterPlatformViewsController->SetFlutterView(mockFlutterView); - surfaceFactory->SetPlatformViewsController(flutterPlatformViewsController); MockFlutterPlatformFactory* factory = [[MockFlutterPlatformFactory new] autorelease]; flutterPlatformViewsController->RegisterViewFactory( @@ -280,7 +277,7 @@ - (void)testAnnouncesRouteChanges { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -346,7 +343,7 @@ - (void)testAnnouncesRouteChangesWhenAddAdditionalRoute { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -430,7 +427,7 @@ - (void)testAnnouncesRouteChangesRemoveRouteInMiddle { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -520,7 +517,7 @@ - (void)testAnnouncesRouteChangesWhenNoNamesRoute { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -588,7 +585,7 @@ - (void)testAnnouncesLayoutChangeWithNilIfLastFocusIsRemoved { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterView = OCMClassMock([FlutterView class]); @@ -655,7 +652,7 @@ - (void)testAnnouncesLayoutChangeWithLastFocused { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterView = OCMClassMock([FlutterView class]); @@ -728,7 +725,7 @@ - (void)testAnnouncesLayoutChangeWhenFocusMovedOutside { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterView = OCMClassMock([FlutterView class]); @@ -803,7 +800,7 @@ - (void)testAnnouncesScrollChangeWithLastFocused { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); id mockFlutterView = OCMClassMock([FlutterView class]); @@ -874,7 +871,7 @@ - (void)testAnnouncesIgnoresRouteChangesWhenModal { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); id mockFlutterView = OCMClassMock([FlutterView class]); id mockFlutterViewController = OCMClassMock([FlutterViewController class]); @@ -942,7 +939,7 @@ - (void)testAccessibilityMessageAfterDeletion { auto platform_view = std::make_unique( /*delegate=*/mock_delegate, /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware, - flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware), + /*platform_views_controller=*/nil, /*task_runners=*/runners); fml::AutoResetWaitableEvent latch; thread_task_runner->PostTask([&] { diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.h b/shell/platform/darwin/ios/ios_external_view_embedder.h index 6c023d1b793e1..71de585c3423c 100644 --- a/shell/platform/darwin/ios/ios_external_view_embedder.h +++ b/shell/platform/darwin/ios/ios_external_view_embedder.h @@ -14,7 +14,7 @@ class IOSExternalViewEmbedder : public ExternalViewEmbedder { public: IOSExternalViewEmbedder(const std::shared_ptr& platform_views_controller, - std::shared_ptr context); + const IOSContext& context); // |ExternalViewEmbedder| virtual ~IOSExternalViewEmbedder() override; @@ -22,7 +22,7 @@ class IOSExternalViewEmbedder : public ExternalViewEmbedder { private: const std::shared_ptr& platform_views_controller_; - std::shared_ptr ios_context_; + const IOSContext& ios_context_; // |ExternalViewEmbedder| SkCanvas* GetRootCanvas() override; diff --git a/shell/platform/darwin/ios/ios_external_view_embedder.mm b/shell/platform/darwin/ios/ios_external_view_embedder.mm index 46cb3014b636f..d463132134acf 100644 --- a/shell/platform/darwin/ios/ios_external_view_embedder.mm +++ b/shell/platform/darwin/ios/ios_external_view_embedder.mm @@ -8,10 +8,8 @@ IOSExternalViewEmbedder::IOSExternalViewEmbedder( const std::shared_ptr& platform_views_controller, - std::shared_ptr context) - : platform_views_controller_(platform_views_controller), ios_context_(context) { - FML_CHECK(ios_context_); -} + const IOSContext& context) + : platform_views_controller_(platform_views_controller), ios_context_(context) {} IOSExternalViewEmbedder::~IOSExternalViewEmbedder() = default; diff --git a/shell/platform/darwin/ios/ios_surface.h b/shell/platform/darwin/ios/ios_surface.h index 0e3d784aefcfb..66ce62de3ecb4 100644 --- a/shell/platform/darwin/ios/ios_surface.h +++ b/shell/platform/darwin/ios/ios_surface.h @@ -6,7 +6,6 @@ #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS_SURFACE_H_ #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" -#import "flutter/shell/platform/darwin/ios/ios_external_view_embedder.h" #include @@ -25,14 +24,8 @@ bool IsIosEmbeddedViewsPreviewEnabled(); class IOSSurface { public: - static std::unique_ptr Create( - std::shared_ptr context, - fml::scoped_nsobject layer, - const std::shared_ptr& external_view_embedder); - - std::shared_ptr GetContext() const; - - std::shared_ptr GetSurfaceExternalViewEmbedder() const; + static std::unique_ptr Create(const IOSContext& context, + fml::scoped_nsobject layer); virtual ~IOSSurface(); @@ -48,13 +41,11 @@ class IOSSurface { virtual std::unique_ptr CreateGPUSurface(GrDirectContext* gr_context = nullptr) = 0; protected: - IOSSurface(std::shared_ptr ios_context, - const std::shared_ptr& external_view_embedder); + explicit IOSSurface(const IOSContext& ios_context); - private: - std::shared_ptr ios_context_; - std::shared_ptr external_view_embedder_; + const IOSContext& ios_context_; + private: FML_DISALLOW_COPY_AND_ASSIGN(IOSSurface); }; diff --git a/shell/platform/darwin/ios/ios_surface.mm b/shell/platform/darwin/ios/ios_surface.mm index 84cd298b318d6..cb7b1afe06d5e 100644 --- a/shell/platform/darwin/ios/ios_surface.mm +++ b/shell/platform/darwin/ios/ios_surface.mm @@ -7,7 +7,7 @@ #import "flutter/shell/platform/darwin/ios/ios_surface_gl.h" #import "flutter/shell/platform/darwin/ios/ios_surface_software.h" -#include "flutter/shell/platform/darwin/ios/rendering_api_selection.h" +#include "flutter/shell/platform/darwin/graphics/rendering_api_selection.h" #if FLUTTER_SHELL_ENABLE_METAL #import "flutter/shell/platform/darwin/ios/ios_surface_metal.h" @@ -15,19 +15,15 @@ namespace flutter { -std::unique_ptr IOSSurface::Create( - std::shared_ptr context, - fml::scoped_nsobject layer, - const std::shared_ptr& external_view_embedder) { +std::unique_ptr IOSSurface::Create(const IOSContext& context, + fml::scoped_nsobject layer) { FML_DCHECK(layer); - FML_DCHECK(context); if ([layer.get() isKindOfClass:[CAEAGLLayer class]]) { return std::make_unique( fml::scoped_nsobject( reinterpret_cast([layer.get() retain])), // EAGL layer - std::move(context), // context - external_view_embedder // external view embedder + std::move(context) // context ); } @@ -37,33 +33,19 @@ return std::make_unique( fml::scoped_nsobject( reinterpret_cast([layer.get() retain])), // Metal layer - std::move(context), // context - external_view_embedder // external view embedder + std::move(context) // context ); } } #endif // FLUTTER_SHELL_ENABLE_METAL - return std::make_unique(std::move(layer), // layer - std::move(context), // context - external_view_embedder // external view embedder + return std::make_unique(std::move(layer), // layer + std::move(context) // context ); } -IOSSurface::IOSSurface(std::shared_ptr ios_context, - const std::shared_ptr& external_view_embedder) - : ios_context_(std::move(ios_context)), external_view_embedder_(external_view_embedder) { - FML_DCHECK(ios_context_); -} +IOSSurface::IOSSurface(const IOSContext& ios_context) : ios_context_(ios_context) {} IOSSurface::~IOSSurface() = default; -std::shared_ptr IOSSurface::GetContext() const { - return ios_context_; -} - -std::shared_ptr IOSSurface::GetSurfaceExternalViewEmbedder() const { - return external_view_embedder_; -} - } // namespace flutter diff --git a/shell/platform/darwin/ios/ios_surface_factory.h b/shell/platform/darwin/ios/ios_surface_factory.h deleted file mode 100644 index 8c5f4d8185ded..0000000000000 --- a/shell/platform/darwin/ios/ios_surface_factory.h +++ /dev/null @@ -1,43 +0,0 @@ -// 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__SURFACE_FACTORY_H_ -#define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS__SURFACE_FACTORY_H_ - -#include - -#import "flutter/shell/platform/darwin/ios/ios_external_view_embedder.h" -#import "flutter/shell/platform/darwin/ios/ios_surface.h" -#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" - -namespace flutter { - -class IOSSurfaceFactory { - public: - static std::shared_ptr Create( - IOSRenderingAPI rendering_api); - - explicit IOSSurfaceFactory(std::shared_ptr ios_context); - - ~IOSSurfaceFactory(); - - void SetPlatformViewsController( - const std::shared_ptr& - platform_views_controller); - - std::unique_ptr CreateSurface( - fml::scoped_nsobject ca_layer); - - std::shared_ptr GetExternalViewEmbedder(); - - private: - std::shared_ptr external_view_embedder_; - std::shared_ptr ios_context_; - - FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceFactory); -}; - -} // namespace flutter - -#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_IOS__SURFACE_FACTORY_H_ diff --git a/shell/platform/darwin/ios/ios_surface_factory.mm b/shell/platform/darwin/ios/ios_surface_factory.mm deleted file mode 100644 index d3d6e8a90b145..0000000000000 --- a/shell/platform/darwin/ios/ios_surface_factory.mm +++ /dev/null @@ -1,37 +0,0 @@ -// 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_surface_factory.h" - -#import "flutter/shell/platform/darwin/ios/ios_context.h" -#import "flutter/shell/platform/darwin/ios/ios_external_view_embedder.h" - -namespace flutter { - -IOSSurfaceFactory::IOSSurfaceFactory(std::shared_ptr ios_context) - : ios_context_(ios_context) {} - -std::shared_ptr IOSSurfaceFactory::Create(IOSRenderingAPI rendering_api) { - std::shared_ptr ios_context = IOSContext::Create(rendering_api); - return std::make_shared(ios_context); -} - -IOSSurfaceFactory::~IOSSurfaceFactory() = default; - -void IOSSurfaceFactory::SetPlatformViewsController( - const std::shared_ptr& platform_views_controller) { - external_view_embedder_.reset( - new IOSExternalViewEmbedder(platform_views_controller, ios_context_)); -} - -std::shared_ptr IOSSurfaceFactory::GetExternalViewEmbedder() { - return external_view_embedder_; -} - -std::unique_ptr IOSSurfaceFactory::CreateSurface( - fml::scoped_nsobject ca_layer) { - return flutter::IOSSurface::Create(ios_context_, ca_layer, external_view_embedder_); -} - -} // namespace flutter diff --git a/shell/platform/darwin/ios/ios_surface_gl.h b/shell/platform/darwin/ios/ios_surface_gl.h index 5345364ce8265..edcfa8a8a44b4 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.h +++ b/shell/platform/darwin/ios/ios_surface_gl.h @@ -8,8 +8,8 @@ #include "flutter/fml/macros.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" #include "flutter/shell/gpu/gpu_surface_gl.h" -#import "flutter/shell/platform/darwin/ios/ios_context.h" -#import "flutter/shell/platform/darwin/ios/ios_render_target_gl.h" +#import "flutter/shell/platform/darwin/graphics/ios_context.h" +#import "flutter/shell/platform/darwin/graphics/ios_render_target_gl.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" @class CAEAGLLayer; @@ -18,9 +18,7 @@ namespace flutter { class IOSSurfaceGL final : public IOSSurface, public GPUSurfaceGLDelegate { public: - IOSSurfaceGL(fml::scoped_nsobject layer, - std::shared_ptr context, - const std::shared_ptr& external_view_embedder = nullptr); + IOSSurfaceGL(fml::scoped_nsobject layer, const IOSContext& context); ~IOSSurfaceGL() override; diff --git a/shell/platform/darwin/ios/ios_surface_gl.mm b/shell/platform/darwin/ios/ios_surface_gl.mm index e15dccb0280a9..87e6a403ea5a8 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.mm +++ b/shell/platform/darwin/ios/ios_surface_gl.mm @@ -6,19 +6,17 @@ #include "flutter/fml/trace_event.h" #include "flutter/shell/gpu/gpu_surface_gl.h" -#import "flutter/shell/platform/darwin/ios/ios_context_gl.h" +#import "flutter/shell/platform/darwin/graphics/ios_context_gl.h" namespace flutter { -static IOSContextGL* CastToGLContext(const std::shared_ptr& context) { - return reinterpret_cast(context.get()); +static const IOSContextGL& CastToGLContext(const IOSContext& context) { + return static_cast(context); } -IOSSurfaceGL::IOSSurfaceGL(fml::scoped_nsobject layer, - std::shared_ptr context, - const std::shared_ptr& external_view_embedder) - : IOSSurface(context, external_view_embedder) { - render_target_ = CastToGLContext(context)->CreateRenderTarget(std::move(layer)); +IOSSurfaceGL::IOSSurfaceGL(fml::scoped_nsobject layer, const IOSContext& context) + : IOSSurface(context) { + render_target_ = CastToGLContext(context).CreateRenderTarget(std::move(layer)); } IOSSurfaceGL::~IOSSurfaceGL() = default; @@ -67,7 +65,7 @@ if (!update_if_necessary) { return std::make_unique(false); } - return GetContext()->MakeCurrent(); + return ios_context_.MakeCurrent(); } // |GPUSurfaceGLDelegate| diff --git a/shell/platform/darwin/ios/ios_surface_metal.h b/shell/platform/darwin/ios/ios_surface_metal.h index 5fe0dbb8a2846..b181fb193601f 100644 --- a/shell/platform/darwin/ios/ios_surface_metal.h +++ b/shell/platform/darwin/ios/ios_surface_metal.h @@ -15,9 +15,7 @@ namespace flutter { class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetal final : public IOSSurface { public: - IOSSurfaceMetal(fml::scoped_nsobject layer, - std::shared_ptr context, - const std::shared_ptr& external_view_embedder); + IOSSurfaceMetal(fml::scoped_nsobject layer, const IOSContext& context); // |IOSSurface| ~IOSSurfaceMetal(); diff --git a/shell/platform/darwin/ios/ios_surface_metal.mm b/shell/platform/darwin/ios/ios_surface_metal.mm index 8dbeaea46321b..639bb479e1f52 100644 --- a/shell/platform/darwin/ios/ios_surface_metal.mm +++ b/shell/platform/darwin/ios/ios_surface_metal.mm @@ -5,26 +5,24 @@ #import "flutter/shell/platform/darwin/ios/ios_surface_metal.h" #include "flutter/shell/gpu/gpu_surface_metal.h" -#import "flutter/shell/platform/darwin/ios/ios_context_metal.h" +#import "flutter/shell/platform/darwin/graphics/ios_context_metal.h" namespace flutter { -static IOSContextMetal* CastToMetalContext(const std::shared_ptr& context) { - return reinterpret_cast(context.get()); +static const IOSContextMetal& CastToMetalContext(const IOSContext& context) { + return static_cast(context); } -IOSSurfaceMetal::IOSSurfaceMetal( - fml::scoped_nsobject layer, - std::shared_ptr context, - const std::shared_ptr& external_view_embedder) - : IOSSurface(std::move(context), external_view_embedder), layer_(std::move(layer)) { +IOSSurfaceMetal::IOSSurfaceMetal(fml::scoped_nsobject layer, + const IOSContext& context) + : IOSSurface(std::move(context)), layer_(std::move(layer)) { if (!layer_) { return; } - auto metal_context = CastToMetalContext(GetContext()); + auto& metal_context = CastToMetalContext(ios_context_); - layer_.get().device = metal_context->GetDevice().get(); + layer_.get().device = metal_context.GetDevice().get(); layer_.get().presentsWithTransaction = YES; is_valid_ = true; @@ -45,11 +43,11 @@ // |IOSSurface| std::unique_ptr IOSSurfaceMetal::CreateGPUSurface(GrDirectContext* /* unused */) { - auto metal_context = CastToMetalContext(GetContext()); + auto& metal_context = CastToMetalContext(ios_context_); - return std::make_unique(layer_, // layer - metal_context->GetMainContext(), // context - metal_context->GetMainCommandQueue() // command queue + return std::make_unique(layer_, // layer + metal_context.GetMainContext(), // context + metal_context.GetMainCommandQueue() // command queue ); } diff --git a/shell/platform/darwin/ios/ios_surface_software.h b/shell/platform/darwin/ios/ios_surface_software.h index 3f86de981a209..a46710625e36e 100644 --- a/shell/platform/darwin/ios/ios_surface_software.h +++ b/shell/platform/darwin/ios/ios_surface_software.h @@ -9,7 +9,7 @@ #include "flutter/fml/macros.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" #include "flutter/shell/gpu/gpu_surface_software.h" -#import "flutter/shell/platform/darwin/ios/ios_context.h" +#import "flutter/shell/platform/darwin/graphics/ios_context.h" #import "flutter/shell/platform/darwin/ios/ios_surface.h" @class CALayer; @@ -18,9 +18,7 @@ namespace flutter { class IOSSurfaceSoftware final : public IOSSurface, public GPUSurfaceSoftwareDelegate { public: - IOSSurfaceSoftware(fml::scoped_nsobject layer, - std::shared_ptr context, - const std::shared_ptr& external_view_embedder); + IOSSurfaceSoftware(fml::scoped_nsobject layer, const IOSContext& context); ~IOSSurfaceSoftware() override; diff --git a/shell/platform/darwin/ios/ios_surface_software.mm b/shell/platform/darwin/ios/ios_surface_software.mm index a945bbb175104..81b42f7a102bd 100644 --- a/shell/platform/darwin/ios/ios_surface_software.mm +++ b/shell/platform/darwin/ios/ios_surface_software.mm @@ -15,11 +15,9 @@ namespace flutter { -IOSSurfaceSoftware::IOSSurfaceSoftware( - fml::scoped_nsobject layer, - std::shared_ptr context, - const std::shared_ptr& external_view_embedder) - : IOSSurface(std::move(context), external_view_embedder), layer_(std::move(layer)) {} +IOSSurfaceSoftware::IOSSurfaceSoftware(fml::scoped_nsobject layer, + const IOSContext& context) + : IOSSurface(std::move(context)), layer_(std::move(layer)) {} IOSSurfaceSoftware::~IOSSurfaceSoftware() = default; diff --git a/shell/platform/darwin/ios/platform_view_ios.h b/shell/platform/darwin/ios/platform_view_ios.h index 0681cfb956617..9a4d70eee2428 100644 --- a/shell/platform/darwin/ios/platform_view_ios.h +++ b/shell/platform/darwin/ios/platform_view_ios.h @@ -13,14 +13,12 @@ #include "flutter/fml/platform/darwin/scoped_nsobject.h" #include "flutter/shell/common/platform_view.h" #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterTexture.h" +#import "flutter/shell/platform/darwin/graphics/ios_context.h" +#import "flutter/shell/platform/darwin/graphics/rendering_api_selection.h" #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h" #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterView.h" #import "flutter/shell/platform/darwin/ios/framework/Source/accessibility_bridge.h" #import "flutter/shell/platform/darwin/ios/framework/Source/platform_message_router.h" -#import "flutter/shell/platform/darwin/ios/ios_context.h" -#import "flutter/shell/platform/darwin/ios/ios_surface.h" -#import "flutter/shell/platform/darwin/ios/ios_surface_factory.h" -#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h" @class FlutterViewController; @@ -40,10 +38,11 @@ namespace flutter { */ class PlatformViewIOS final : public PlatformView { public: - explicit PlatformViewIOS(PlatformView::Delegate& delegate, - IOSRenderingAPI rendering_api, - std::shared_ptr surface_factory, - flutter::TaskRunners task_runners); + explicit PlatformViewIOS( + PlatformView::Delegate& delegate, + IOSRenderingAPI rendering_api, + const std::shared_ptr& platform_views_controller, + flutter::TaskRunners task_runners); ~PlatformViewIOS() override; @@ -106,7 +105,7 @@ class PlatformViewIOS final : public PlatformView { /// information to Dart. class AccessibilityBridgePtr { public: - AccessibilityBridgePtr(const std::function& set_semantics_enabled); + explicit AccessibilityBridgePtr(const std::function& set_semantics_enabled); AccessibilityBridgePtr(const std::function& set_semantics_enabled, AccessibilityBridge* bridge); ~AccessibilityBridgePtr(); @@ -125,8 +124,8 @@ class PlatformViewIOS final : public PlatformView { // used on the raster thread we need to protect it with a mutex. std::mutex ios_surface_mutex_; std::unique_ptr ios_surface_; - std::shared_ptr ios_context_; - std::shared_ptr ios_surface_factory_; + const std::unique_ptr ios_context_; + const std::shared_ptr& platform_views_controller_; PlatformMessageRouter platform_message_router_; AccessibilityBridgePtr accessibility_bridge_; fml::scoped_nsprotocol text_input_plugin_; diff --git a/shell/platform/darwin/ios/platform_view_ios.mm b/shell/platform/darwin/ios/platform_view_ios.mm index fb151d6d515e2..932e0aa4a8b3d 100644 --- a/shell/platform/darwin/ios/platform_view_ios.mm +++ b/shell/platform/darwin/ios/platform_view_ios.mm @@ -45,13 +45,14 @@ } } -PlatformViewIOS::PlatformViewIOS(PlatformView::Delegate& delegate, - IOSRenderingAPI rendering_api, - std::shared_ptr surface_factory, - flutter::TaskRunners task_runners) +PlatformViewIOS::PlatformViewIOS( + PlatformView::Delegate& delegate, + IOSRenderingAPI rendering_api, + const std::shared_ptr& platform_views_controller, + flutter::TaskRunners task_runners) : PlatformView(delegate, std::move(task_runners)), ios_context_(IOSContext::Create(rendering_api)), - ios_surface_factory_(surface_factory), + platform_views_controller_(platform_views_controller), accessibility_bridge_([this](bool enabled) { PlatformView::SetSemanticsEnabled(enabled); }) {} PlatformViewIOS::~PlatformViewIOS() = default; @@ -107,7 +108,7 @@ "before attaching to PlatformViewIOS."; auto flutter_view = static_cast(owner_controller_.get().view); auto ca_layer = fml::scoped_nsobject{[[flutter_view layer] retain]}; - ios_surface_ = ios_surface_factory_->CreateSurface(ca_layer); + ios_surface_ = IOSSurface::Create(*ios_context_.get(), ca_layer); FML_DCHECK(ios_surface_ != nullptr); if (accessibility_bridge_) { @@ -142,7 +143,7 @@ // |PlatformView| std::shared_ptr PlatformViewIOS::CreateExternalViewEmbedder() { - return ios_surface_factory_->GetExternalViewEmbedder(); + return std::make_shared(platform_views_controller_, *ios_context_.get()); } // |PlatformView|