From d1fa8c563d4feb0f53ef4807b2d5a5b2a954865d Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Thu, 18 Oct 2018 15:51:49 -0700 Subject: [PATCH 1/8] Plumb the iOS PlatformViewsController into flow. 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. --- flow/BUILD.gn | 1 + flow/compositor_context.cc | 12 ++++---- flow/compositor_context.h | 6 ++++ flow/embedded_views.h | 30 +++++++++++++++++++ flow/layers/layer.h | 2 ++ flow/layers/layer_tree.cc | 4 ++- flow/layers/platform_view_layer.cc | 6 ++-- flow/raster_cache.cc | 24 +++++++-------- shell/common/rasterizer.cc | 11 +++---- shell/common/surface.cc | 4 +++ shell/common/surface.h | 3 ++ shell/gpu/gpu_surface_gl.cc | 5 ++++ shell/gpu/gpu_surface_gl.h | 6 ++++ shell/gpu/gpu_surface_software.cc | 9 ++++++ shell/gpu/gpu_surface_software.h | 6 ++++ .../framework/Source/FlutterPlatformViews.mm | 6 ++++ .../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 | 7 ++++- shell/platform/darwin/ios/ios_surface_gl.mm | 8 ++++- .../darwin/ios/ios_surface_software.h | 7 ++++- .../darwin/ios/ios_surface_software.mm | 9 ++++-- 26 files changed, 174 insertions(+), 35 deletions(-) create mode 100644 flow/embedded_views.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..c7a62e526ca7e 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, + ViewEmbedder* 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, + ViewEmbedder* 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..daf50cd31fc61 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, + ViewEmbedder* view_embedder, const SkMatrix& root_surface_transformation, bool instrumentation_enabled); @@ -33,6 +35,8 @@ class CompositorContext { SkCanvas* canvas() { return canvas_; } + ViewEmbedder* 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_; + ViewEmbedder* 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, + ViewEmbedder* 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..c387c866321ca --- /dev/null +++ b/flow/embedded_views.h @@ -0,0 +1,30 @@ +// 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 EmbeddedViewCompositingParams { + public: + double x; + double y; + double width; + double height; +}; + +class ViewEmbedder : public fml::RefCountedThreadSafe { + public: + virtual void CompositeEmbeddedView(int view_id, + EmbeddedViewCompositingParams& params) {} + + virtual ~ViewEmbedder() {} +}; + +} // namespace flow + +#endif // FLUTTER_FLOW_EMBEDDED_VIEWS_H_ diff --git a/flow/layers/layer.h b/flow/layers/layer.h index 50fd3b63b277d..b2c096751d016 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; + ViewEmbedder* 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..2d0590ff86a16 100644 --- a/flow/layers/platform_view_layer.cc +++ b/flow/layers/platform_view_layer.cc @@ -16,6 +16,8 @@ void PlatformViewLayer::Preroll(PrerollContext* context, size_.height())); } -void PlatformViewLayer::Paint(PaintContext& context) const {} - +void PlatformViewLayer::Paint(PaintContext& context) const { + EmbeddedViewCompositingParams params; + context.view_embedder->CompositeEmbeddedView(view_id_, params); +} } // namespace flow diff --git a/flow/raster_cache.cc b/flow/raster_cache.cc index a9246227fa107..5b7873d5dd680 100644 --- a/flow/raster_cache.cc +++ b/flow/raster_cache.cc @@ -153,18 +153,18 @@ void RasterCache::Prepare(PrerollContext* context, entry.access_count = ClampSize(entry.access_count + 1, 0, threshold_); entry.used_this_frame = true; if (!entry.image.is_valid()) { - entry.image = Rasterize(context->gr_context, ctm, context->dst_color_space, - checkerboard_images_, layer->paint_bounds(), - [layer, context](SkCanvas* canvas) { - Layer::PaintContext paintContext = { - *canvas, - context->frame_time, - context->engine_time, - context->texture_registry, - context->raster_cache, - context->checkerboard_offscreen_layers}; - layer->Paint(paintContext); - }); + entry.image = + Rasterize(context->gr_context, ctm, context->dst_color_space, + checkerboard_images_, layer->paint_bounds(), + [layer, context](SkCanvas* canvas) { + Layer::PaintContext paintContext = { + *canvas, + // TODO(amirh): do we need a view embedded here? + nullptr, context->frame_time, context->engine_time, + context->texture_registry, context->raster_cache, + context->checkerboard_offscreen_layers}; + layer->Paint(paintContext); + }); } } diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index 9a870326dd2d5..b33b21ce643b5 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_->GetViewEmbedder(), + surface_->GetRootTransformation(), true); if (canvas) { canvas->clear(SK_ColorTRANSPARENT); @@ -197,9 +198,9 @@ static sk_sp ScreenshotLayerTreeAsPicture( SkMatrix root_surface_transformation; root_surface_transformation.reset(); - auto frame = - compositor_context.AcquireFrame(nullptr, recorder.getRecordingCanvas(), - root_surface_transformation, false); + auto frame = compositor_context.AcquireFrame( + nullptr, recorder.getRecordingCanvas(), nullptr, + root_surface_transformation, false); frame->Raster(*tree, true); @@ -249,7 +250,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..ec24b0c9d9eb3 100644 --- a/shell/common/surface.cc +++ b/shell/common/surface.cc @@ -64,4 +64,8 @@ Surface::Surface() = default; Surface::~Surface() = default; +flow::ViewEmbedder* Surface::GetViewEmbedder() { + return nullptr; +} + } // namespace shell diff --git a/shell/common/surface.h b/shell/common/surface.h index beef9765da490..4125c71bcff90 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::ViewEmbedder* GetViewEmbedder(); + 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..11acfcc499e21 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::ViewEmbedder* GPUSurfaceGL::GetViewEmbedder() { + return delegate_->GetViewEmbedder(); +} + } // namespace shell diff --git a/shell/gpu/gpu_surface_gl.h b/shell/gpu/gpu_surface_gl.h index 26184141bfd67..3260edc53f2cc 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,8 @@ class GPUSurfaceGLDelegate { return matrix; } + virtual flow::ViewEmbedder* GetViewEmbedder() { return nullptr; } + using GLProcResolver = std::function; virtual GLProcResolver GetGLProcResolver() const { return nullptr; } @@ -58,6 +61,9 @@ class GPUSurfaceGL : public Surface { // |shell::Surface| GrContext* GetContext() override; + // |shell::Surface| + flow::ViewEmbedder* GetViewEmbedder() 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..342e4fb68de10 100644 --- a/shell/gpu/gpu_surface_software.cc +++ b/shell/gpu/gpu_surface_software.cc @@ -9,6 +9,10 @@ namespace shell { +flow::ViewEmbedder* GPUSurfaceSoftwareDelegate::GetViewEmbedder() { + return nullptr; +} + GPUSurfaceSoftware::GPUSurfaceSoftware(GPUSurfaceSoftwareDelegate* delegate) : delegate_(delegate), weak_factory_(this) {} @@ -75,4 +79,9 @@ GrContext* GPUSurfaceSoftware::GetContext() { return nullptr; } +// |shell::Surface| +flow::ViewEmbedder* GPUSurfaceSoftware::GetViewEmbedder() { + return delegate_->GetViewEmbedder(); +} + } // namespace shell diff --git a/shell/gpu/gpu_surface_software.h b/shell/gpu/gpu_surface_software.h index 95940c4702454..76d9b641d480a 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::ViewEmbedder* GetViewEmbedder(); }; class GPUSurfaceSoftware : public Surface { @@ -37,6 +40,9 @@ class GPUSurfaceSoftware : public Surface { // |shell::Surface| GrContext* GetContext() override; + // |shell::Surface| + flow::ViewEmbedder* GetViewEmbedder() 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..8e766780a33f2 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -85,4 +85,10 @@ fml::scoped_nsobject>([factory retain]); } +void FlutterPlatformViewsController::CompositeEmbeddedView( + int view_id, + flow::EmbeddedViewCompositingParams& params) { + // TODO(amirh): implements 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..18fc9bed3946a 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::ViewEmbedder { public: FlutterPlatformViewsController(NSObject* messenger); void RegisterViewFactory(NSObject* factory, NSString* factoryId); + void CompositeEmbeddedView(int view_id, flow::EmbeddedViewCompositingParams& 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..5513fad5986f4 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::GetViewEmbedder 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..ee12eed7b7e65 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::ViewEmbedder*)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..db706bebc9d18 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h @@ -7,6 +7,8 @@ #include "flutter/fml/memory/weak_ptr.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h" +#include "flutter/flow/embedded_views.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::ViewEmbedder*)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..47755ffc26d68 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::ViewEmbedder* (^GetViewEmbedder)(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..414236149e569 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.h +++ b/shell/platform/darwin/ios/ios_surface_gl.h @@ -17,7 +17,7 @@ namespace shell { class IOSSurfaceGL : public IOSSurface, public GPUSurfaceGLDelegate { public: - IOSSurfaceGL(fml::scoped_nsobject layer); + IOSSurfaceGL(fml::scoped_nsobject layer, ::shell::GetViewEmbedder get_view_embedder); ~IOSSurfaceGL() override; @@ -39,9 +39,14 @@ class IOSSurfaceGL : public IOSSurface, public GPUSurfaceGLDelegate { bool UseOffscreenSurface() const override; + // |shell::GPUSurfaceGLDelegate| + flow::ViewEmbedder* GetViewEmbedder() override; + private: IOSGLContext context_; + fml::scoped_nsprotocol<::shell::GetViewEmbedder> 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..e0d022d94e913 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::GetViewEmbedder 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::ViewEmbedder* IOSSurfaceGL::GetViewEmbedder() { + 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..b5a308def6c9a 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::GetViewEmbedder 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::ViewEmbedder* GetViewEmbedder() override; + private: fml::scoped_nsobject layer_; + fml::scoped_nsprotocol<::shell::GetViewEmbedder> 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..e247e61657925 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::GetViewEmbedder get_view_embedder) + : layer_(std::move(layer)), get_view_embedder_([get_view_embedder retain]) { UpdateStorageSizeIfNecessary(); } @@ -125,4 +126,8 @@ return true; } +flow::ViewEmbedder* IOSSurfaceSoftware::GetViewEmbedder() { + return get_view_embedder_.get()(); +} + } // namespace shell From 8a896976fdc25b6183568c653a197408cca161a7 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Tue, 23 Oct 2018 16:33:12 -0700 Subject: [PATCH 2/8] review comments followup --- flow/embedded_views.h | 10 +++++--- flow/layers/platform_view_layer.cc | 2 +- flow/raster_cache.cc | 25 ++++++++++--------- shell/common/rasterizer.cc | 2 ++ .../framework/Source/FlutterPlatformViews.mm | 5 ++-- .../Source/FlutterPlatformViews_Internal.h | 2 +- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/flow/embedded_views.h b/flow/embedded_views.h index c387c866321ca..027d8d61654a7 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -9,7 +9,7 @@ namespace flow { -class EmbeddedViewCompositingParams { +class EmbeddedViewParams { public: double x; double y; @@ -17,10 +17,14 @@ class EmbeddedViewCompositingParams { double height; }; -class ViewEmbedder : public fml::RefCountedThreadSafe { +// 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 ViewEmbedder { public: + // Must be called on the UI thread. virtual void CompositeEmbeddedView(int view_id, - EmbeddedViewCompositingParams& params) {} + const EmbeddedViewParams& params) {} virtual ~ViewEmbedder() {} }; diff --git a/flow/layers/platform_view_layer.cc b/flow/layers/platform_view_layer.cc index 2d0590ff86a16..3fa3d1f3fa1cb 100644 --- a/flow/layers/platform_view_layer.cc +++ b/flow/layers/platform_view_layer.cc @@ -17,7 +17,7 @@ void PlatformViewLayer::Preroll(PrerollContext* context, } void PlatformViewLayer::Paint(PaintContext& context) const { - EmbeddedViewCompositingParams params; + EmbeddedViewParams params; context.view_embedder->CompositeEmbeddedView(view_id_, params); } } // namespace flow diff --git a/flow/raster_cache.cc b/flow/raster_cache.cc index 5b7873d5dd680..017b907e161f7 100644 --- a/flow/raster_cache.cc +++ b/flow/raster_cache.cc @@ -153,18 +153,19 @@ void RasterCache::Prepare(PrerollContext* context, entry.access_count = ClampSize(entry.access_count + 1, 0, threshold_); entry.used_this_frame = true; if (!entry.image.is_valid()) { - entry.image = - Rasterize(context->gr_context, ctm, context->dst_color_space, - checkerboard_images_, layer->paint_bounds(), - [layer, context](SkCanvas* canvas) { - Layer::PaintContext paintContext = { - *canvas, - // TODO(amirh): do we need a view embedded here? - nullptr, context->frame_time, context->engine_time, - context->texture_registry, context->raster_cache, - context->checkerboard_offscreen_layers}; - layer->Paint(paintContext); - }); + entry.image = Rasterize(context->gr_context, ctm, context->dst_color_space, + checkerboard_images_, layer->paint_bounds(), + [layer, context](SkCanvas* canvas) { + Layer::PaintContext paintContext = { + *canvas, + nullptr, + context->frame_time, + context->engine_time, + context->texture_registry, + context->raster_cache, + context->checkerboard_offscreen_layers}; + layer->Paint(paintContext); + }); } } diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index b33b21ce643b5..b1cd331dc6fb7 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -198,6 +198,8 @@ static sk_sp ScreenshotLayerTreeAsPicture( SkMatrix root_surface_transformation; root_surface_transformation.reset(); + // 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); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 8e766780a33f2..0b1d7e698138e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -85,9 +85,8 @@ fml::scoped_nsobject>([factory retain]); } -void FlutterPlatformViewsController::CompositeEmbeddedView( - int view_id, - flow::EmbeddedViewCompositingParams& params) { +void FlutterPlatformViewsController::CompositeEmbeddedView(int view_id, + const flow::EmbeddedViewParams& params) { // TODO(amirh): implements this. } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index 18fc9bed3946a..ab717343391b9 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -20,7 +20,7 @@ class FlutterPlatformViewsController : public flow::ViewEmbedder { void RegisterViewFactory(NSObject* factory, NSString* factoryId); - void CompositeEmbeddedView(int view_id, flow::EmbeddedViewCompositingParams& params); + void CompositeEmbeddedView(int view_id, const flow::EmbeddedViewParams& params); private: fml::scoped_nsobject channel_; From 750909fa4ad985646c375f14223a45ca07a8d680 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Wed, 24 Oct 2018 15:31:05 -0700 Subject: [PATCH 3/8] disallow copy and assign --- flow/embedded_views.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flow/embedded_views.h b/flow/embedded_views.h index 027d8d61654a7..2661b8e0ac565 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -22,11 +22,15 @@ class EmbeddedViewParams { // FlutterPlatformViewsController which is owned by FlutterViewController. class ViewEmbedder { public: + ViewEmbedder() {} + // Must be called on the UI thread. virtual void CompositeEmbeddedView(int view_id, const EmbeddedViewParams& params) {} virtual ~ViewEmbedder() {} + + FML_DISALLOW_COPY_AND_ASSIGN(ViewEmbedder); }; } // namespace flow From 43a8c25877f355fd88eed33bf12c146935121c38 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Wed, 24 Oct 2018 16:11:42 -0700 Subject: [PATCH 4/8] review comments followup --- flow/compositor_context.cc | 4 ++-- flow/compositor_context.h | 8 ++++---- flow/embedded_views.h | 12 ++++-------- flow/layers/layer.h | 2 +- shell/common/rasterizer.cc | 2 +- shell/common/surface.cc | 2 +- shell/common/surface.h | 2 +- shell/gpu/gpu_surface_gl.cc | 4 ++-- shell/gpu/gpu_surface_gl.h | 6 ++++-- shell/gpu/gpu_surface_software.cc | 7 ++++--- shell/gpu/gpu_surface_software.h | 4 ++-- .../framework/Source/FlutterPlatformViews_Internal.h | 2 +- .../darwin/ios/framework/Source/FlutterView.mm | 2 +- .../ios/framework/Source/FlutterViewController.mm | 2 +- .../Source/FlutterViewController_Internal.h | 2 +- shell/platform/darwin/ios/ios_surface.h | 2 +- shell/platform/darwin/ios/ios_surface_gl.h | 7 ++++--- shell/platform/darwin/ios/ios_surface_gl.mm | 4 ++-- shell/platform/darwin/ios/ios_surface_software.h | 6 +++--- shell/platform/darwin/ios/ios_surface_software.mm | 4 ++-- 20 files changed, 42 insertions(+), 42 deletions(-) diff --git a/flow/compositor_context.cc b/flow/compositor_context.cc index c7a62e526ca7e..ba74a8de27bfe 100644 --- a/flow/compositor_context.cc +++ b/flow/compositor_context.cc @@ -32,7 +32,7 @@ void CompositorContext::EndFrame(ScopedFrame& frame, std::unique_ptr CompositorContext::AcquireFrame( GrContext* gr_context, SkCanvas* canvas, - ViewEmbedder* view_embedder, + ExternalViewEmbedder* view_embedder, const SkMatrix& root_surface_transformation, bool instrumentation_enabled) { return std::make_unique(*this, gr_context, canvas, view_embedder, @@ -44,7 +44,7 @@ CompositorContext::ScopedFrame::ScopedFrame( CompositorContext& context, GrContext* gr_context, SkCanvas* canvas, - ViewEmbedder* view_embedder, + ExternalViewEmbedder* view_embedder, const SkMatrix& root_surface_transformation, bool instrumentation_enabled) : context_(context), diff --git a/flow/compositor_context.h b/flow/compositor_context.h index daf50cd31fc61..ca35dc4f609ce 100644 --- a/flow/compositor_context.h +++ b/flow/compositor_context.h @@ -27,7 +27,7 @@ class CompositorContext { ScopedFrame(CompositorContext& context, GrContext* gr_context, SkCanvas* canvas, - ViewEmbedder* view_embedder, + ExternalViewEmbedder* view_embedder, const SkMatrix& root_surface_transformation, bool instrumentation_enabled); @@ -35,7 +35,7 @@ class CompositorContext { SkCanvas* canvas() { return canvas_; } - ViewEmbedder* view_embedder() { return view_embedder_; } + ExternalViewEmbedder* view_embedder() { return view_embedder_; } CompositorContext& context() const { return context_; } @@ -51,7 +51,7 @@ class CompositorContext { CompositorContext& context_; GrContext* gr_context_; SkCanvas* canvas_; - ViewEmbedder* view_embedder_; + ExternalViewEmbedder* view_embedder_; const SkMatrix& root_surface_transformation_; const bool instrumentation_enabled_; @@ -65,7 +65,7 @@ class CompositorContext { virtual std::unique_ptr AcquireFrame( GrContext* gr_context, SkCanvas* canvas, - ViewEmbedder* view_embedder, + ExternalViewEmbedder* view_embedder, const SkMatrix& root_surface_transformation, bool instrumentation_enabled); diff --git a/flow/embedded_views.h b/flow/embedded_views.h index 2661b8e0ac565..55a5ba5671b2d 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -11,26 +11,22 @@ namespace flow { class EmbeddedViewParams { public: - double x; - double y; - double width; - double height; }; // 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 ViewEmbedder { +class ExternalViewEmbedder { public: - ViewEmbedder() {} + ExternalViewEmbedder() {} // Must be called on the UI thread. virtual void CompositeEmbeddedView(int view_id, const EmbeddedViewParams& params) {} - virtual ~ViewEmbedder() {} + virtual ~ExternalViewEmbedder() {} - FML_DISALLOW_COPY_AND_ASSIGN(ViewEmbedder); + FML_DISALLOW_COPY_AND_ASSIGN(ExternalViewEmbedder); }; } // namespace flow diff --git a/flow/layers/layer.h b/flow/layers/layer.h index b2c096751d016..dbd101d6cc9b8 100644 --- a/flow/layers/layer.h +++ b/flow/layers/layer.h @@ -65,7 +65,7 @@ class Layer { struct PaintContext { SkCanvas& canvas; - ViewEmbedder* view_embedder; + ExternalViewEmbedder* view_embedder; const Stopwatch& frame_time; const Stopwatch& engine_time; TextureRegistry& texture_registry; diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index b1cd331dc6fb7..47fcdf024760c 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -167,7 +167,7 @@ bool Rasterizer::DrawToSurface(flow::LayerTree& layer_tree) { auto canvas = frame->SkiaCanvas(); auto compositor_frame = compositor_context_->AcquireFrame( - surface_->GetContext(), canvas, surface_->GetViewEmbedder(), + surface_->GetContext(), canvas, surface_->GetExternalViewEmbedder(), surface_->GetRootTransformation(), true); if (canvas) { diff --git a/shell/common/surface.cc b/shell/common/surface.cc index ec24b0c9d9eb3..54fc364fa96fa 100644 --- a/shell/common/surface.cc +++ b/shell/common/surface.cc @@ -64,7 +64,7 @@ Surface::Surface() = default; Surface::~Surface() = default; -flow::ViewEmbedder* Surface::GetViewEmbedder() { +flow::ExternalViewEmbedder* Surface::GetExternalViewEmbedder() { return nullptr; } diff --git a/shell/common/surface.h b/shell/common/surface.h index 4125c71bcff90..324ef4cb6df42 100644 --- a/shell/common/surface.h +++ b/shell/common/surface.h @@ -56,7 +56,7 @@ class Surface { virtual GrContext* GetContext() = 0; - virtual flow::ViewEmbedder* GetViewEmbedder(); + 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 11acfcc499e21..4a421b9dae38b 100644 --- a/shell/gpu/gpu_surface_gl.cc +++ b/shell/gpu/gpu_surface_gl.cc @@ -341,8 +341,8 @@ GrContext* GPUSurfaceGL::GetContext() { } // |shell::Surface| -flow::ViewEmbedder* GPUSurfaceGL::GetViewEmbedder() { - return delegate_->GetViewEmbedder(); +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 3260edc53f2cc..1b768c18cbb1a 100644 --- a/shell/gpu/gpu_surface_gl.h +++ b/shell/gpu/gpu_surface_gl.h @@ -36,7 +36,9 @@ class GPUSurfaceGLDelegate { return matrix; } - virtual flow::ViewEmbedder* GetViewEmbedder() { return nullptr; } + virtual flow::ExternalViewEmbedder* GetExternalViewEmbedder() { + return nullptr; + } using GLProcResolver = std::function; @@ -62,7 +64,7 @@ class GPUSurfaceGL : public Surface { GrContext* GetContext() override; // |shell::Surface| - flow::ViewEmbedder* GetViewEmbedder() override; + flow::ExternalViewEmbedder* GetExternalViewEmbedder() override; private: GPUSurfaceGLDelegate* delegate_; diff --git a/shell/gpu/gpu_surface_software.cc b/shell/gpu/gpu_surface_software.cc index 342e4fb68de10..3678f7ad28264 100644 --- a/shell/gpu/gpu_surface_software.cc +++ b/shell/gpu/gpu_surface_software.cc @@ -9,7 +9,8 @@ namespace shell { -flow::ViewEmbedder* GPUSurfaceSoftwareDelegate::GetViewEmbedder() { +flow::ExternalViewEmbedder* +GPUSurfaceSoftwareDelegate::GetExternalViewEmbedder() { return nullptr; } @@ -80,8 +81,8 @@ GrContext* GPUSurfaceSoftware::GetContext() { } // |shell::Surface| -flow::ViewEmbedder* GPUSurfaceSoftware::GetViewEmbedder() { - return delegate_->GetViewEmbedder(); +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 76d9b641d480a..29ddb126eb6b3 100644 --- a/shell/gpu/gpu_surface_software.h +++ b/shell/gpu/gpu_surface_software.h @@ -19,7 +19,7 @@ class GPUSurfaceSoftwareDelegate { virtual bool PresentBackingStore(sk_sp backing_store) = 0; - virtual flow::ViewEmbedder* GetViewEmbedder(); + virtual flow::ExternalViewEmbedder* GetExternalViewEmbedder(); }; class GPUSurfaceSoftware : public Surface { @@ -41,7 +41,7 @@ class GPUSurfaceSoftware : public Surface { GrContext* GetContext() override; // |shell::Surface| - flow::ViewEmbedder* GetViewEmbedder() override; + flow::ExternalViewEmbedder* GetExternalViewEmbedder() override; private: GPUSurfaceSoftwareDelegate* delegate_; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h index ab717343391b9..9c9d80435606d 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h @@ -14,7 +14,7 @@ namespace shell { -class FlutterPlatformViewsController : public flow::ViewEmbedder { +class FlutterPlatformViewsController : public flow::ExternalViewEmbedder { public: FlutterPlatformViewsController(NSObject* messenger); diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index 5513fad5986f4..60e51501d55ed 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -93,7 +93,7 @@ + (Class)layerClass { } - (std::unique_ptr)createSurface { - ::shell::GetViewEmbedder get_view_embedder = [[^() { + ::shell::GetExternalViewEmbedder get_view_embedder = [[^() { return [[self flutterViewController] viewEmbedder]; } copy] autorelease]; if ([self.layer isKindOfClass:[CAEAGLLayer class]]) { diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index ee12eed7b7e65..3636899fa4700 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -124,7 +124,7 @@ - (void)performCommonViewControllerInitialization { return _weakFactory->GetWeakPtr(); } -- (flow::ViewEmbedder*)viewEmbedder { +- (flow::ExternalViewEmbedder*)viewEmbedder { return _platformViewsController.get(); } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h index db706bebc9d18..f2b41ee27a5e6 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h @@ -19,7 +19,7 @@ @property(readonly) fml::scoped_nsobject engine; -- (flow::ViewEmbedder*)viewEmbedder; +- (flow::ExternalViewEmbedder*)viewEmbedder; @end diff --git a/shell/platform/darwin/ios/ios_surface.h b/shell/platform/darwin/ios/ios_surface.h index 47755ffc26d68..c756aae4fba08 100644 --- a/shell/platform/darwin/ios/ios_surface.h +++ b/shell/platform/darwin/ios/ios_surface.h @@ -13,7 +13,7 @@ namespace shell { -typedef flow::ViewEmbedder* (^GetViewEmbedder)(void); +typedef flow::ExternalViewEmbedder* (^GetExternalViewEmbedder)(void); class IOSSurface { public: diff --git a/shell/platform/darwin/ios/ios_surface_gl.h b/shell/platform/darwin/ios/ios_surface_gl.h index 414236149e569..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, ::shell::GetViewEmbedder get_view_embedder); + IOSSurfaceGL(fml::scoped_nsobject layer, + ::shell::GetExternalViewEmbedder get_view_embedder); ~IOSSurfaceGL() override; @@ -40,12 +41,12 @@ class IOSSurfaceGL : public IOSSurface, public GPUSurfaceGLDelegate { bool UseOffscreenSurface() const override; // |shell::GPUSurfaceGLDelegate| - flow::ViewEmbedder* GetViewEmbedder() override; + flow::ExternalViewEmbedder* GetExternalViewEmbedder() override; private: IOSGLContext context_; - fml::scoped_nsprotocol<::shell::GetViewEmbedder> get_view_embedder_; + 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 e0d022d94e913..e834e352afec0 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.mm +++ b/shell/platform/darwin/ios/ios_surface_gl.mm @@ -10,7 +10,7 @@ namespace shell { IOSSurfaceGL::IOSSurfaceGL(fml::scoped_nsobject layer, - ::shell::GetViewEmbedder get_view_embedder) + ::shell::GetExternalViewEmbedder get_view_embedder) : context_(std::move(layer)), get_view_embedder_([get_view_embedder retain]) {} IOSSurfaceGL::~IOSSurfaceGL() = default; @@ -58,7 +58,7 @@ return IsValid() ? context_.PresentRenderBuffer() : false; } -flow::ViewEmbedder* IOSSurfaceGL::GetViewEmbedder() { +flow::ExternalViewEmbedder* IOSSurfaceGL::GetExternalViewEmbedder() { return get_view_embedder_.get()(); } diff --git a/shell/platform/darwin/ios/ios_surface_software.h b/shell/platform/darwin/ios/ios_surface_software.h index b5a308def6c9a..d0d9ce4049e8a 100644 --- a/shell/platform/darwin/ios/ios_surface_software.h +++ b/shell/platform/darwin/ios/ios_surface_software.h @@ -17,7 +17,7 @@ namespace shell { class IOSSurfaceSoftware final : public IOSSurface, public GPUSurfaceSoftwareDelegate { public: IOSSurfaceSoftware(fml::scoped_nsobject layer, - ::shell::GetViewEmbedder get_view_embedder); + ::shell::GetExternalViewEmbedder get_view_embedder); ~IOSSurfaceSoftware() override; @@ -40,11 +40,11 @@ class IOSSurfaceSoftware final : public IOSSurface, public GPUSurfaceSoftwareDel bool PresentBackingStore(sk_sp backing_store) override; // |shell::GPUSurfaceSoftwareDelegate| - flow::ViewEmbedder* GetViewEmbedder() override; + flow::ExternalViewEmbedder* GetExternalViewEmbedder() override; private: fml::scoped_nsobject layer_; - fml::scoped_nsprotocol<::shell::GetViewEmbedder> get_view_embedder_; + 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 e247e61657925..c79ce8215f7bc 100644 --- a/shell/platform/darwin/ios/ios_surface_software.mm +++ b/shell/platform/darwin/ios/ios_surface_software.mm @@ -16,7 +16,7 @@ namespace shell { IOSSurfaceSoftware::IOSSurfaceSoftware(fml::scoped_nsobject layer, - ::shell::GetViewEmbedder get_view_embedder) + ::shell::GetExternalViewEmbedder get_view_embedder) : layer_(std::move(layer)), get_view_embedder_([get_view_embedder retain]) { UpdateStorageSizeIfNecessary(); } @@ -126,7 +126,7 @@ return true; } -flow::ViewEmbedder* IOSSurfaceSoftware::GetViewEmbedder() { +flow::ExternalViewEmbedder* IOSSurfaceSoftware::GetExternalViewEmbedder() { return get_view_embedder_.get()(); } From 4eee1ac01bce0ae8c569dedcfa29444e93723f1c Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Wed, 24 Oct 2018 16:21:40 -0700 Subject: [PATCH 5/8] review comments followup --- flow/embedded_views.h | 4 ++-- .../darwin/ios/framework/Source/FlutterPlatformViews.mm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flow/embedded_views.h b/flow/embedded_views.h index 55a5ba5671b2d..577922f42133f 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -18,13 +18,13 @@ class EmbeddedViewParams { // FlutterPlatformViewsController which is owned by FlutterViewController. class ExternalViewEmbedder { public: - ExternalViewEmbedder() {} + ExternalViewEmbedder() = default; // Must be called on the UI thread. virtual void CompositeEmbeddedView(int view_id, const EmbeddedViewParams& params) {} - virtual ~ExternalViewEmbedder() {} + virtual ~ExternalViewEmbedder() = default; FML_DISALLOW_COPY_AND_ASSIGN(ExternalViewEmbedder); }; diff --git a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm index 0b1d7e698138e..9b63070c6f9d9 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm @@ -87,7 +87,7 @@ void FlutterPlatformViewsController::CompositeEmbeddedView(int view_id, const flow::EmbeddedViewParams& params) { - // TODO(amirh): implements this. + // TODO(amirh): implement this. } } // namespace shell From ff1b379dff82940b904909a42e19d1a5c14991d7 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Wed, 24 Oct 2018 17:01:38 -0700 Subject: [PATCH 6/8] update licenses file --- ci/licenses_golden/licenses_flutter | 1 + 1 file changed, 1 insertion(+) 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 From 5a6c0876fca248f47b14459b74e12df1c9674fa2 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 26 Oct 2018 08:58:21 -0700 Subject: [PATCH 7/8] make platform view layer a no op when not supported --- flow/layers/platform_view_layer.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flow/layers/platform_view_layer.cc b/flow/layers/platform_view_layer.cc index 3fa3d1f3fa1cb..42fdd91954b62 100644 --- a/flow/layers/platform_view_layer.cc +++ b/flow/layers/platform_view_layer.cc @@ -17,6 +17,11 @@ void PlatformViewLayer::Preroll(PrerollContext* context, } 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); } From d8c2c66a28ea2319fdde0778af46f0e91e4f24b0 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 26 Oct 2018 14:13:12 -0700 Subject: [PATCH 8/8] sort includes --- .../ios/framework/Source/FlutterViewController_Internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h index f2b41ee27a5e6..38c2c9040dd33 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h @@ -5,9 +5,9 @@ #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/flow/embedded_views.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"