99#include < utility>
1010
1111#include " flutter/fml/platform/darwin/scoped_nsobject.h"
12+ #include " flutter/shell/gpu/gpu_surface_metal_impeller.h"
1213#include " flutter/shell/gpu/gpu_surface_metal_skia.h"
14+ #include " flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalImpeller.h"
1315#include " flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
1416
1517namespace flutter {
2931// non-Objective-C TUs.
3032class DarwinContextMetal {
3133 public:
32- DarwinContextMetal ()
33- : context_([[FlutterDarwinContextMetalSkia alloc ] initWithDefaultMTLDevice ]),
34- offscreen_texture_ (CreateOffscreenTexture([context_.get () device ])) {}
34+ explicit DarwinContextMetal (bool impeller)
35+ : context_(impeller ? nil : [[FlutterDarwinContextMetalSkia alloc ] initWithDefaultMTLDevice ]),
36+ impeller_context_(impeller ? [[FlutterDarwinContextMetalImpeller alloc ] init ] : nil ),
37+ offscreen_texture_(CreateOffscreenTexture(
38+ impeller ? [impeller_context_ context ]->GetMTLDevice () : [context_ device])) {}
3539
3640 ~DarwinContextMetal () = default ;
3741
42+ fml::scoped_nsobject<FlutterDarwinContextMetalImpeller> impeller_context () const {
43+ return impeller_context_;
44+ }
45+
3846 fml::scoped_nsobject<FlutterDarwinContextMetalSkia> context () const { return context_; }
3947
4048 fml::scoped_nsprotocol<id <MTLTexture >> offscreen_texture () const { return offscreen_texture_; }
@@ -48,6 +56,7 @@ GPUMTLTextureInfo offscreen_texture_info() const {
4856
4957 private:
5058 const fml::scoped_nsobject<FlutterDarwinContextMetalSkia> context_;
59+ const fml::scoped_nsobject<FlutterDarwinContextMetalImpeller> impeller_context_;
5160 const fml::scoped_nsprotocol<id <MTLTexture >> offscreen_texture_;
5261
5362 FML_DISALLOW_COPY_AND_ASSIGN (DarwinContextMetal);
@@ -61,11 +70,15 @@ GPUMTLTextureInfo offscreen_texture_info() const {
6170 std::shared_ptr<ShellTestExternalViewEmbedder> shell_test_external_view_embedder)
6271 : ShellTestPlatformView(delegate, task_runners),
6372 GPUSurfaceMetalDelegate(MTLRenderTargetType::kMTLTexture ),
64- metal_context_(std::make_unique<DarwinContextMetal>()),
73+ metal_context_(std::make_unique<DarwinContextMetal>(GetSettings().enable_impeller )),
6574 create_vsync_waiter_(std::move(create_vsync_waiter)),
6675 vsync_clock_(std::move(vsync_clock)),
6776 shell_test_external_view_embedder_(std::move(shell_test_external_view_embedder)) {
68- FML_CHECK ([metal_context_->context () mainContext ] != nil );
77+ if (GetSettings ().enable_impeller ) {
78+ FML_CHECK ([metal_context_->impeller_context () context ] != nil );
79+ } else {
80+ FML_CHECK ([metal_context_->context () mainContext ] != nil );
81+ }
6982}
7083
7184ShellTestPlatformViewMetal::~ShellTestPlatformViewMetal () = default ;
@@ -93,10 +106,19 @@ GPUMTLTextureInfo offscreen_texture_info() const {
93106
94107// |PlatformView|
95108std::unique_ptr<Surface> ShellTestPlatformViewMetal::CreateRenderingSurface () {
109+ if (GetSettings ().enable_impeller ) {
110+ return std::make_unique<GPUSurfaceMetalImpeller>(this ,
111+ [metal_context_->impeller_context () context ]);
112+ }
96113 return std::make_unique<GPUSurfaceMetalSkia>(this , [metal_context_->context () mainContext ],
97114 MsaaSampleCount::kNone );
98115}
99116
117+ // |PlatformView|
118+ std::shared_ptr<impeller::Context> ShellTestPlatformViewMetal::GetImpellerContext () const {
119+ return [metal_context_->impeller_context () context ];
120+ }
121+
100122// |GPUSurfaceMetalDelegate|
101123GPUCAMetalLayerHandle ShellTestPlatformViewMetal::GetCAMetalLayer (const SkISize& frame_info) const {
102124 FML_CHECK (false ) << " A Metal Delegate configured with MTLRenderTargetType::kMTLTexture was asked "
0 commit comments