From df85722fa0efdd7ea00317158134297de9b6f408 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 26 Oct 2018 14:26:59 -0700 Subject: [PATCH] Plumb the iOS PlatformViewsController into flow. (#6603) For flow to manipulate the embedded UIViews during the paint traversal it needs some hook in PaintContext. This PR introduces a ViewEmbeder interface that is implemented by the iOS PlatformViewsController and plumbs it into PaintContext. The ViewEmbedder interface is mainly a place holder at this point, as this PR is focused on just the plumbing. --- ci/licenses_golden/licenses_flutter | 1 + flow/BUILD.gn | 1 + flow/compositor_context.cc | 12 +++---- flow/compositor_context.h | 6 ++++ flow/embedded_views.h | 34 +++++++++++++++++++ flow/layers/layer.h | 2 ++ flow/layers/layer_tree.cc | 4 ++- flow/layers/platform_view_layer.cc | 11 ++++-- flow/raster_cache.cc | 1 + shell/common/rasterizer.cc | 13 ++++--- shell/common/surface.cc | 4 +++ shell/common/surface.h | 3 ++ shell/gpu/gpu_surface_gl.cc | 5 +++ shell/gpu/gpu_surface_gl.h | 8 +++++ shell/gpu/gpu_surface_software.cc | 10 ++++++ shell/gpu/gpu_surface_software.h | 6 ++++ .../framework/Source/FlutterPlatformViews.mm | 5 +++ .../Source/FlutterPlatformViews_Internal.h | 5 ++- .../darwin/ios/framework/Source/FlutterView.h | 1 + .../ios/framework/Source/FlutterView.mm | 25 ++++++++++++-- .../framework/Source/FlutterViewController.mm | 6 +++- .../Source/FlutterViewController_Internal.h | 4 +++ shell/platform/darwin/ios/ios_surface.h | 2 ++ shell/platform/darwin/ios/ios_surface_gl.h | 8 ++++- shell/platform/darwin/ios/ios_surface_gl.mm | 8 ++++- .../darwin/ios/ios_surface_software.h | 7 +++- .../darwin/ios/ios_surface_software.mm | 9 +++-- 27 files changed, 178 insertions(+), 23 deletions(-) create mode 100644 flow/embedded_views.h diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 3c40ce365f34d..e854c429bbde8 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -11,6 +11,7 @@ ORIGIN: ../../../flutter/flow/layers/physical_shape_layer.cc + ../../../LICENSE TYPE: LicenseType.bsd FILE: ../../../flutter/flow/debug_print.cc FILE: ../../../flutter/flow/debug_print.h +FILE: ../../../flutter/flow/embedded_views.h FILE: ../../../flutter/flow/export_node.h FILE: ../../../flutter/flow/layers/physical_shape_layer.cc FILE: ../../../flutter/flow/layers/physical_shape_layer.h diff --git a/flow/BUILD.gn b/flow/BUILD.gn index c476b4c5bdf48..3613ad9a29bbd 100644 --- a/flow/BUILD.gn +++ b/flow/BUILD.gn @@ -8,6 +8,7 @@ source_set("flow") { "compositor_context.h", "debug_print.cc", "debug_print.h", + "embedded_views.h", "instrumentation.cc", "instrumentation.h", "layers/backdrop_filter_layer.cc", diff --git a/flow/compositor_context.cc b/flow/compositor_context.cc index e5a725ef6478c..ba74a8de27bfe 100644 --- a/flow/compositor_context.cc +++ b/flow/compositor_context.cc @@ -32,25 +32,25 @@ void CompositorContext::EndFrame(ScopedFrame& frame, std::unique_ptr CompositorContext::AcquireFrame( GrContext* gr_context, SkCanvas* canvas, + ExternalViewEmbedder* view_embedder, const SkMatrix& root_surface_transformation, bool instrumentation_enabled) { - return std::make_unique(*this, // - gr_context, // - canvas, // - root_surface_transformation, // - instrumentation_enabled // - ); + return std::make_unique(*this, gr_context, canvas, view_embedder, + root_surface_transformation, + instrumentation_enabled); } CompositorContext::ScopedFrame::ScopedFrame( CompositorContext& context, GrContext* gr_context, SkCanvas* canvas, + ExternalViewEmbedder* view_embedder, const SkMatrix& root_surface_transformation, bool instrumentation_enabled) : context_(context), gr_context_(gr_context), canvas_(canvas), + view_embedder_(view_embedder), root_surface_transformation_(root_surface_transformation), instrumentation_enabled_(instrumentation_enabled) { context_.BeginFrame(*this, instrumentation_enabled_); diff --git a/flow/compositor_context.h b/flow/compositor_context.h index 522c5359934ff..ca35dc4f609ce 100644 --- a/flow/compositor_context.h +++ b/flow/compositor_context.h @@ -8,6 +8,7 @@ #include #include +#include "flutter/flow/embedded_views.h" #include "flutter/flow/instrumentation.h" #include "flutter/flow/raster_cache.h" #include "flutter/flow/texture.h" @@ -26,6 +27,7 @@ class CompositorContext { ScopedFrame(CompositorContext& context, GrContext* gr_context, SkCanvas* canvas, + ExternalViewEmbedder* view_embedder, const SkMatrix& root_surface_transformation, bool instrumentation_enabled); @@ -33,6 +35,8 @@ class CompositorContext { SkCanvas* canvas() { return canvas_; } + ExternalViewEmbedder* view_embedder() { return view_embedder_; } + CompositorContext& context() const { return context_; } const SkMatrix& root_surface_transformation() const { @@ -47,6 +51,7 @@ class CompositorContext { CompositorContext& context_; GrContext* gr_context_; SkCanvas* canvas_; + ExternalViewEmbedder* view_embedder_; const SkMatrix& root_surface_transformation_; const bool instrumentation_enabled_; @@ -60,6 +65,7 @@ class CompositorContext { virtual std::unique_ptr AcquireFrame( GrContext* gr_context, SkCanvas* canvas, + ExternalViewEmbedder* view_embedder, const SkMatrix& root_surface_transformation, bool instrumentation_enabled); diff --git a/flow/embedded_views.h b/flow/embedded_views.h new file mode 100644 index 0000000000000..577922f42133f --- /dev/null +++ b/flow/embedded_views.h @@ -0,0 +1,34 @@ +// Copyright 2017 The Chromium 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_FLOW_EMBEDDED_VIEWS_H_ +#define FLUTTER_FLOW_EMBEDDED_VIEWS_H_ + +#include "flutter/fml/memory/ref_counted.h" + +namespace flow { + +class EmbeddedViewParams { + public: +}; + +// This is only used on iOS when running in a non headless mode, +// in this case ViewEmbedded is a reference to the +// FlutterPlatformViewsController which is owned by FlutterViewController. +class ExternalViewEmbedder { + public: + ExternalViewEmbedder() = default; + + // Must be called on the UI thread. + virtual void CompositeEmbeddedView(int view_id, + const EmbeddedViewParams& params) {} + + virtual ~ExternalViewEmbedder() = default; + + FML_DISALLOW_COPY_AND_ASSIGN(ExternalViewEmbedder); +}; + +} // namespace flow + +#endif // FLUTTER_FLOW_EMBEDDED_VIEWS_H_ diff --git a/flow/layers/layer.h b/flow/layers/layer.h index 50fd3b63b277d..dbd101d6cc9b8 100644 --- a/flow/layers/layer.h +++ b/flow/layers/layer.h @@ -8,6 +8,7 @@ #include #include +#include "flutter/flow/embedded_views.h" #include "flutter/flow/instrumentation.h" #include "flutter/flow/raster_cache.h" #include "flutter/flow/texture.h" @@ -64,6 +65,7 @@ class Layer { struct PaintContext { SkCanvas& canvas; + ExternalViewEmbedder* view_embedder; const Stopwatch& frame_time; const Stopwatch& engine_time; TextureRegistry& texture_registry; diff --git a/flow/layers/layer_tree.cc b/flow/layers/layer_tree.cc index de28918193576..6896bb112b6a1 100644 --- a/flow/layers/layer_tree.cc +++ b/flow/layers/layer_tree.cc @@ -68,6 +68,7 @@ void LayerTree::Paint(CompositorContext::ScopedFrame& frame, TRACE_EVENT0("flutter", "LayerTree::Paint"); Layer::PaintContext context = { *frame.canvas(), + frame.view_embedder(), frame.context().frame_time(), frame.context().engine_time(), frame.context().texture_registry(), @@ -106,7 +107,8 @@ sk_sp LayerTree::Flatten(const SkRect& bounds) { }; Layer::PaintContext paint_context = { - *canvas, // canvas + *canvas, // canvas + nullptr, unused_stopwatch, // frame time (dont care) unused_stopwatch, // engine time (dont care) unused_texture_registry, // texture registry (not supported) diff --git a/flow/layers/platform_view_layer.cc b/flow/layers/platform_view_layer.cc index 0a6a17244e0df..42fdd91954b62 100644 --- a/flow/layers/platform_view_layer.cc +++ b/flow/layers/platform_view_layer.cc @@ -16,6 +16,13 @@ void PlatformViewLayer::Preroll(PrerollContext* context, size_.height())); } -void PlatformViewLayer::Paint(PaintContext& context) const {} - +void PlatformViewLayer::Paint(PaintContext& context) const { + if (context.view_embedder == nullptr) { + FML_LOG(ERROR) << "Trying to embed a platform view but the PaintContext " + "does not support embedding"; + return; + } + EmbeddedViewParams params; + context.view_embedder->CompositeEmbeddedView(view_id_, params); +} } // namespace flow diff --git a/flow/raster_cache.cc b/flow/raster_cache.cc index a9246227fa107..017b907e161f7 100644 --- a/flow/raster_cache.cc +++ b/flow/raster_cache.cc @@ -158,6 +158,7 @@ void RasterCache::Prepare(PrerollContext* context, [layer, context](SkCanvas* canvas) { Layer::PaintContext paintContext = { *canvas, + nullptr, context->frame_time, context->engine_time, context->texture_registry, diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index 9a870326dd2d5..47fcdf024760c 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -167,7 +167,8 @@ bool Rasterizer::DrawToSurface(flow::LayerTree& layer_tree) { auto canvas = frame->SkiaCanvas(); auto compositor_frame = compositor_context_->AcquireFrame( - surface_->GetContext(), canvas, surface_->GetRootTransformation(), true); + surface_->GetContext(), canvas, surface_->GetExternalViewEmbedder(), + surface_->GetRootTransformation(), true); if (canvas) { canvas->clear(SK_ColorTRANSPARENT); @@ -197,9 +198,11 @@ static sk_sp ScreenshotLayerTreeAsPicture( SkMatrix root_surface_transformation; root_surface_transformation.reset(); - auto frame = - compositor_context.AcquireFrame(nullptr, recorder.getRecordingCanvas(), - root_surface_transformation, false); + // TODO(amirh): figure out how to take a screenshot with embedded UIView. + // https://github.com/flutter/flutter/issues/23435 + auto frame = compositor_context.AcquireFrame( + nullptr, recorder.getRecordingCanvas(), nullptr, + root_surface_transformation, false); frame->Raster(*tree, true); @@ -249,7 +252,7 @@ static sk_sp ScreenshotLayerTreeAsImage( root_surface_transformation.reset(); auto frame = compositor_context.AcquireFrame( - surface_context, canvas, root_surface_transformation, false); + surface_context, canvas, nullptr, root_surface_transformation, false); canvas->clear(SK_ColorTRANSPARENT); frame->Raster(*tree, true); canvas->flush(); diff --git a/shell/common/surface.cc b/shell/common/surface.cc index f0b3ba19d93ab..54fc364fa96fa 100644 --- a/shell/common/surface.cc +++ b/shell/common/surface.cc @@ -64,4 +64,8 @@ Surface::Surface() = default; Surface::~Surface() = default; +flow::ExternalViewEmbedder* Surface::GetExternalViewEmbedder() { + return nullptr; +} + } // namespace shell diff --git a/shell/common/surface.h b/shell/common/surface.h index beef9765da490..324ef4cb6df42 100644 --- a/shell/common/surface.h +++ b/shell/common/surface.h @@ -8,6 +8,7 @@ #include #include "flutter/flow/compositor_context.h" +#include "flutter/flow/embedded_views.h" #include "flutter/fml/macros.h" #include "third_party/skia/include/core/SkCanvas.h" @@ -55,6 +56,8 @@ class Surface { virtual GrContext* GetContext() = 0; + virtual flow::ExternalViewEmbedder* GetExternalViewEmbedder(); + private: FML_DISALLOW_COPY_AND_ASSIGN(Surface); }; diff --git a/shell/gpu/gpu_surface_gl.cc b/shell/gpu/gpu_surface_gl.cc index 153f68073ba0d..4a421b9dae38b 100644 --- a/shell/gpu/gpu_surface_gl.cc +++ b/shell/gpu/gpu_surface_gl.cc @@ -340,4 +340,9 @@ GrContext* GPUSurfaceGL::GetContext() { return context_.get(); } +// |shell::Surface| +flow::ExternalViewEmbedder* GPUSurfaceGL::GetExternalViewEmbedder() { + return delegate_->GetExternalViewEmbedder(); +} + } // namespace shell diff --git a/shell/gpu/gpu_surface_gl.h b/shell/gpu/gpu_surface_gl.h index 26184141bfd67..1b768c18cbb1a 100644 --- a/shell/gpu/gpu_surface_gl.h +++ b/shell/gpu/gpu_surface_gl.h @@ -8,6 +8,7 @@ #include #include +#include "flutter/flow/embedded_views.h" #include "flutter/fml/macros.h" #include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/surface.h" @@ -35,6 +36,10 @@ class GPUSurfaceGLDelegate { return matrix; } + virtual flow::ExternalViewEmbedder* GetExternalViewEmbedder() { + return nullptr; + } + using GLProcResolver = std::function; virtual GLProcResolver GetGLProcResolver() const { return nullptr; } @@ -58,6 +63,9 @@ class GPUSurfaceGL : public Surface { // |shell::Surface| GrContext* GetContext() override; + // |shell::Surface| + flow::ExternalViewEmbedder* GetExternalViewEmbedder() override; + private: GPUSurfaceGLDelegate* delegate_; GPUSurfaceGLDelegate::GLProcResolver proc_resolver_; diff --git a/shell/gpu/gpu_surface_software.cc b/shell/gpu/gpu_surface_software.cc index 7598aa243d33e..3678f7ad28264 100644 --- a/shell/gpu/gpu_surface_software.cc +++ b/shell/gpu/gpu_surface_software.cc @@ -9,6 +9,11 @@ namespace shell { +flow::ExternalViewEmbedder* +GPUSurfaceSoftwareDelegate::GetExternalViewEmbedder() { + return nullptr; +} + GPUSurfaceSoftware::GPUSurfaceSoftware(GPUSurfaceSoftwareDelegate* delegate) : delegate_(delegate), weak_factory_(this) {} @@ -75,4 +80,9 @@ GrContext* GPUSurfaceSoftware::GetContext() { return nullptr; } +// |shell::Surface| +flow::ExternalViewEmbedder* GPUSurfaceSoftware::GetExternalViewEmbedder() { + return delegate_->GetExternalViewEmbedder(); +} + } // namespace shell diff --git a/shell/gpu/gpu_surface_software.h b/shell/gpu/gpu_surface_software.h index 95940c4702454..29ddb126eb6b3 100644 --- a/shell/gpu/gpu_surface_software.h +++ b/shell/gpu/gpu_surface_software.h @@ -5,6 +5,7 @@ #ifndef FLUTTER_SHELL_GPU_GPU_SURFACE_SOFTWARE_H_ #define FLUTTER_SHELL_GPU_GPU_SURFACE_SOFTWARE_H_ +#include "flutter/flow/embedded_views.h" #include "flutter/fml/macros.h" #include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/surface.h" @@ -17,6 +18,8 @@ class GPUSurfaceSoftwareDelegate { virtual sk_sp AcquireBackingStore(const SkISize& size) = 0; virtual bool PresentBackingStore(sk_sp backing_store) = 0; + + virtual flow::ExternalViewEmbedder* GetExternalViewEmbedder(); }; class GPUSurfaceSoftware : public Surface { @@ -37,6 +40,9 @@ class GPUSurfaceSoftware : public Surface { // |shell::Surface| GrContext* GetContext() override; + // |shell::Surface| + flow::ExternalViewEmbedder* GetExternalViewEmbedder() override; + private: GPUSurfaceSoftwareDelegate* delegate_; fml::WeakPtrFactory weak_factory_; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 9da977da8c993..9b63070c6f9d9 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -85,4 +85,9 @@ fml::scoped_nsobject>([factory retain]); } +void FlutterPlatformViewsController::CompositeEmbeddedView(int view_id, + const flow::EmbeddedViewParams& params) { + // TODO(amirh): implement this. +} + } // namespace shell diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 620bec26d3ee5..9c9d80435606d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -5,6 +5,7 @@ #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_ #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERPLATFORMVIEWS_INTERNAL_H_ +#include "flutter/flow/embedded_views.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" #include "flutter/shell/common/shell.h" #include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterBinaryMessenger.h" @@ -13,12 +14,14 @@ namespace shell { -class FlutterPlatformViewsController { +class FlutterPlatformViewsController : public flow::ExternalViewEmbedder { public: FlutterPlatformViewsController(NSObject* messenger); void RegisterViewFactory(NSObject* factory, NSString* factoryId); + void CompositeEmbeddedView(int view_id, const flow::EmbeddedViewParams& params); + private: fml::scoped_nsobject channel_; std::map>> factories_; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.h b/shell/platform/darwin/ios/framework/Source/FlutterView.h index e9cd37281e63a..8b4bb5a010217 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.h @@ -9,6 +9,7 @@ #include +#include "flutter/flow/embedded_views.h" #include "flutter/fml/memory/weak_ptr.h" #include "flutter/shell/common/shell.h" #include "flutter/shell/platform/darwin/ios/ios_surface.h" diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index 63ee05acc832c..60e51501d55ed 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -12,6 +12,7 @@ #include "flutter/fml/trace_event.h" #include "flutter/shell/common/platform_view.h" #include "flutter/shell/common/rasterizer.h" +#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h" #include "flutter/shell/platform/darwin/ios/ios_surface_gl.h" #include "flutter/shell/platform/darwin/ios/ios_surface_software.h" #include "third_party/skia/include/utils/mac/SkCGUtils.h" @@ -54,6 +55,23 @@ - (instancetype)initWithDelegate:(id)delegate opaque: return self; } +- (FlutterViewController*)flutterViewController { + // Find the first view controller in the responder chain and see if it is a FlutterViewController. + for (UIResponder* responder = self.nextResponder; responder != nil; + responder = responder.nextResponder) { + if ([responder isKindOfClass:[UIViewController class]]) { + if ([responder isKindOfClass:[FlutterViewController class]]) { + return reinterpret_cast(responder); + } else { + // Should only happen if a non-FlutterViewController tries to somehow (via dynamic class + // resolution or reparenting) set a FlutterView as its view. + return nil; + } + } + } + return nil; +} + - (void)layoutSubviews { if ([self.layer isKindOfClass:[CAEAGLLayer class]]) { CAEAGLLayer* layer = reinterpret_cast(self.layer); @@ -75,13 +93,16 @@ + (Class)layerClass { } - (std::unique_ptr)createSurface { + ::shell::GetExternalViewEmbedder get_view_embedder = [[^() { + return [[self flutterViewController] viewEmbedder]; + } copy] autorelease]; if ([self.layer isKindOfClass:[CAEAGLLayer class]]) { fml::scoped_nsobject eagl_layer( reinterpret_cast([self.layer retain])); - return std::make_unique(std::move(eagl_layer)); + return std::make_unique(std::move(eagl_layer), get_view_embedder); } else { fml::scoped_nsobject layer(reinterpret_cast([self.layer retain])); - return std::make_unique(std::move(layer)); + return std::make_unique(std::move(layer), get_view_embedder); } } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index ea56bfc2dfca7..3636899fa4700 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -124,6 +124,10 @@ - (void)performCommonViewControllerInitialization { return _weakFactory->GetWeakPtr(); } +- (flow::ExternalViewEmbedder*)viewEmbedder { + return _platformViewsController.get(); +} + - (void)setupNotificationCenterObservers { NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; [center addObserver:self @@ -953,4 +957,4 @@ - (NSObject*)valuePublishedByPlugin:(NSString*)pluginKey { return [_engine.get() valuePublishedByPlugin:pluginKey]; } -@end \ No newline at end of file +@end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h index 75e820907cc0a..38c2c9040dd33 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h @@ -5,8 +5,10 @@ #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEWCONTROLLER_INTERNAL_H_ #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEWCONTROLLER_INTERNAL_H_ +#include "flutter/flow/embedded_views.h" #include "flutter/fml/memory/weak_ptr.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" +#include "flutter/shell/common/shell.h" #include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h" #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h" @@ -17,6 +19,8 @@ @property(readonly) fml::scoped_nsobject engine; +- (flow::ExternalViewEmbedder*)viewEmbedder; + @end #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEWCONTROLLER_INTERNAL_H_ diff --git a/shell/platform/darwin/ios/ios_surface.h b/shell/platform/darwin/ios/ios_surface.h index 8011905db4d68..c756aae4fba08 100644 --- a/shell/platform/darwin/ios/ios_surface.h +++ b/shell/platform/darwin/ios/ios_surface.h @@ -13,6 +13,8 @@ namespace shell { +typedef flow::ExternalViewEmbedder* (^GetExternalViewEmbedder)(void); + class IOSSurface { public: IOSSurface(); diff --git a/shell/platform/darwin/ios/ios_surface_gl.h b/shell/platform/darwin/ios/ios_surface_gl.h index 1a3fc3ed3b406..b7b604adb86f7 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.h +++ b/shell/platform/darwin/ios/ios_surface_gl.h @@ -17,7 +17,8 @@ namespace shell { class IOSSurfaceGL : public IOSSurface, public GPUSurfaceGLDelegate { public: - IOSSurfaceGL(fml::scoped_nsobject layer); + IOSSurfaceGL(fml::scoped_nsobject layer, + ::shell::GetExternalViewEmbedder get_view_embedder); ~IOSSurfaceGL() override; @@ -39,9 +40,14 @@ class IOSSurfaceGL : public IOSSurface, public GPUSurfaceGLDelegate { bool UseOffscreenSurface() const override; + // |shell::GPUSurfaceGLDelegate| + flow::ExternalViewEmbedder* GetExternalViewEmbedder() override; + private: IOSGLContext context_; + fml::scoped_nsprotocol<::shell::GetExternalViewEmbedder> get_view_embedder_; + FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceGL); }; diff --git a/shell/platform/darwin/ios/ios_surface_gl.mm b/shell/platform/darwin/ios/ios_surface_gl.mm index 253531c4800aa..e834e352afec0 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.mm +++ b/shell/platform/darwin/ios/ios_surface_gl.mm @@ -9,7 +9,9 @@ namespace shell { -IOSSurfaceGL::IOSSurfaceGL(fml::scoped_nsobject layer) : context_(std::move(layer)) {} +IOSSurfaceGL::IOSSurfaceGL(fml::scoped_nsobject layer, + ::shell::GetExternalViewEmbedder get_view_embedder) + : context_(std::move(layer)), get_view_embedder_([get_view_embedder retain]) {} IOSSurfaceGL::~IOSSurfaceGL() = default; @@ -56,4 +58,8 @@ return IsValid() ? context_.PresentRenderBuffer() : false; } +flow::ExternalViewEmbedder* IOSSurfaceGL::GetExternalViewEmbedder() { + return get_view_embedder_.get()(); +} + } // namespace shell diff --git a/shell/platform/darwin/ios/ios_surface_software.h b/shell/platform/darwin/ios/ios_surface_software.h index 25ab355b91cf2..d0d9ce4049e8a 100644 --- a/shell/platform/darwin/ios/ios_surface_software.h +++ b/shell/platform/darwin/ios/ios_surface_software.h @@ -16,7 +16,8 @@ namespace shell { class IOSSurfaceSoftware final : public IOSSurface, public GPUSurfaceSoftwareDelegate { public: - IOSSurfaceSoftware(fml::scoped_nsobject layer); + IOSSurfaceSoftware(fml::scoped_nsobject layer, + ::shell::GetExternalViewEmbedder get_view_embedder); ~IOSSurfaceSoftware() override; @@ -38,8 +39,12 @@ class IOSSurfaceSoftware final : public IOSSurface, public GPUSurfaceSoftwareDel // |shell::GPUSurfaceSoftwareDelegate| bool PresentBackingStore(sk_sp backing_store) override; + // |shell::GPUSurfaceSoftwareDelegate| + flow::ExternalViewEmbedder* GetExternalViewEmbedder() override; + private: fml::scoped_nsobject layer_; + fml::scoped_nsprotocol<::shell::GetExternalViewEmbedder> get_view_embedder_; sk_sp sk_surface_; FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceSoftware); diff --git a/shell/platform/darwin/ios/ios_surface_software.mm b/shell/platform/darwin/ios/ios_surface_software.mm index dba1fd7ce1fe9..c79ce8215f7bc 100644 --- a/shell/platform/darwin/ios/ios_surface_software.mm +++ b/shell/platform/darwin/ios/ios_surface_software.mm @@ -15,8 +15,9 @@ namespace shell { -IOSSurfaceSoftware::IOSSurfaceSoftware(fml::scoped_nsobject layer) - : layer_(std::move(layer)) { +IOSSurfaceSoftware::IOSSurfaceSoftware(fml::scoped_nsobject layer, + ::shell::GetExternalViewEmbedder get_view_embedder) + : layer_(std::move(layer)), get_view_embedder_([get_view_embedder retain]) { UpdateStorageSizeIfNecessary(); } @@ -125,4 +126,8 @@ return true; } +flow::ExternalViewEmbedder* IOSSurfaceSoftware::GetExternalViewEmbedder() { + return get_view_embedder_.get()(); +} + } // namespace shell