From 13453c82a4ada303a50012e3a62754c2666fb8c0 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Thu, 8 Nov 2018 16:08:43 -0800 Subject: [PATCH 1/2] Synchronize Flutter's rendering with CA. Right now we do it whenever the platform views preview flag is on. This is less efficient, filed https://github.com/flutter/flutter/issues/24133 to only do this when there's a platform view in the tree. --- flow/embedded_views.h | 2 +- shell/common/rasterizer.cc | 2 +- .../darwin/ios/framework/Source/FlutterOverlayView.mm | 5 +++++ .../darwin/ios/framework/Source/FlutterView.mm | 10 ++++++++++ shell/platform/darwin/ios/ios_surface_gl.h | 2 +- shell/platform/darwin/ios/ios_surface_gl.mm | 8 ++++++-- shell/platform/darwin/ios/ios_surface_software.h | 2 +- shell/platform/darwin/ios/ios_surface_software.mm | 2 +- 8 files changed, 26 insertions(+), 7 deletions(-) diff --git a/flow/embedded_views.h b/flow/embedded_views.h index e98c98a6e1cc7..81c67de9784b5 100644 --- a/flow/embedded_views.h +++ b/flow/embedded_views.h @@ -27,7 +27,7 @@ class ExternalViewEmbedder { public: ExternalViewEmbedder() = default; - virtual void SetFrameSize(SkISize frame_size) = 0; + virtual void BeginFrame(SkISize frame_size) = 0; virtual void PrerollCompositeEmbeddedView(int view_id) = 0; diff --git a/shell/common/rasterizer.cc b/shell/common/rasterizer.cc index 29d534b2a4430..9e30a4c561a4e 100644 --- a/shell/common/rasterizer.cc +++ b/shell/common/rasterizer.cc @@ -165,7 +165,7 @@ bool Rasterizer::DrawToSurface(flow::LayerTree& layer_tree) { auto external_view_embedder = surface_->GetExternalViewEmbedder(); if (external_view_embedder != nullptr) { - external_view_embedder->SetFrameSize(layer_tree.frame_size()); + external_view_embedder->BeginFrame(layer_tree.frame_size()); } auto compositor_frame = compositor_context_->AcquireFrame( diff --git a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm index 6b7d8bbf093e5..83f59d24e0b81 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm @@ -71,6 +71,11 @@ + (Class)layerClass { - (std::unique_ptr)createGLSurfaceWithContext: (std::shared_ptr)gl_context { fml::scoped_nsobject eagl_layer(reinterpret_cast([self.layer retain])); + // TODO(amirh): We can lower this to iOS 8.0 once we have a Metal rendering backend. + // https://github.com/flutter/flutter/issues/24132 + if (@available(iOS 9.0, *)) { + eagl_layer.get().presentsWithTransaction = YES; + } return std::make_unique(eagl_layer, std::move(gl_context)); } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index fbf3270925828..892ef38f6e075 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -79,6 +79,16 @@ + (Class)layerClass { if ([self.layer isKindOfClass:[CAEAGLLayer class]]) { fml::scoped_nsobject eagl_layer( reinterpret_cast([self.layer retain])); + if ([[[NSBundle mainBundle] objectForInfoDictionaryKey:@(shell::kEmbeddedViewsPreview)] + boolValue]) { + // TODO(amirh): We can lower this to iOS 8.0 once we have a Metal rendering backend. + // https://github.com/flutter/flutter/issues/24132 + if (@available(iOS 9.0, *)) { + // TODO(amirh): only do this if there's an embedded view. + // https://github.com/flutter/flutter/issues/24133 + eagl_layer.get().presentsWithTransaction = YES; + } + } return std::make_unique(std::move(eagl_layer), [_delegate platformViewsController]); } else { diff --git a/shell/platform/darwin/ios/ios_surface_gl.h b/shell/platform/darwin/ios/ios_surface_gl.h index f0e898a1bb00e..9f7013c29b100 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.h +++ b/shell/platform/darwin/ios/ios_surface_gl.h @@ -51,7 +51,7 @@ class IOSSurfaceGL : public IOSSurface, flow::ExternalViewEmbedder* GetExternalViewEmbedder() override; // |flow::ExternalViewEmbedder| - void SetFrameSize(SkISize frame_size) override; + void BeginFrame(SkISize frame_size) override; // |flow::ExternalViewEmbedder| void PrerollCompositeEmbeddedView(int view_id) override; diff --git a/shell/platform/darwin/ios/ios_surface_gl.mm b/shell/platform/darwin/ios/ios_surface_gl.mm index 236b05dacae05..cd0bb093d87d4 100644 --- a/shell/platform/darwin/ios/ios_surface_gl.mm +++ b/shell/platform/darwin/ios/ios_surface_gl.mm @@ -82,10 +82,11 @@ } } -void IOSSurfaceGL::SetFrameSize(SkISize frame_size) { +void IOSSurfaceGL::BeginFrame(SkISize frame_size) { FlutterPlatformViewsController* platform_views_controller = GetPlatformViewsController(); FML_CHECK(platform_views_controller != nullptr); platform_views_controller->SetFrameSize(frame_size); + [CATransaction begin]; } void IOSSurfaceGL::PrerollCompositeEmbeddedView(int view_id) { @@ -111,7 +112,10 @@ if (platform_views_controller == nullptr) { return true; } - return platform_views_controller->SubmitFrame(true, std::move(context), context_); + + bool submitted = platform_views_controller->SubmitFrame(true, std::move(context), context_); + [CATransaction commit]; + return submitted; } } // namespace shell diff --git a/shell/platform/darwin/ios/ios_surface_software.h b/shell/platform/darwin/ios/ios_surface_software.h index 1642497f27dfd..5106bdfb0aa3e 100644 --- a/shell/platform/darwin/ios/ios_surface_software.h +++ b/shell/platform/darwin/ios/ios_surface_software.h @@ -46,7 +46,7 @@ class IOSSurfaceSoftware final : public IOSSurface, flow::ExternalViewEmbedder* GetExternalViewEmbedder() override; // |flow::ExternalViewEmbedder| - void SetFrameSize(SkISize frame_size) override; + void BeginFrame(SkISize frame_size) override; // |flow::ExternalViewEmbedder| void PrerollCompositeEmbeddedView(int view_id) override; diff --git a/shell/platform/darwin/ios/ios_surface_software.mm b/shell/platform/darwin/ios/ios_surface_software.mm index a1017439c0057..5d120ef47c061 100644 --- a/shell/platform/darwin/ios/ios_surface_software.mm +++ b/shell/platform/darwin/ios/ios_surface_software.mm @@ -134,7 +134,7 @@ } } -void IOSSurfaceSoftware::SetFrameSize(SkISize frame_size) { +void IOSSurfaceSoftware::BeginFrame(SkISize frame_size) { FlutterPlatformViewsController* platform_views_controller = GetPlatformViewsController(); FML_CHECK(platform_views_controller != nullptr); platform_views_controller->SetFrameSize(frame_size); From 4ce8cd765cddf9c9e9cf6c06e180d9eccdf426f1 Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Fri, 9 Nov 2018 11:34:18 -0800 Subject: [PATCH 2/2] check the preview flag with the common function --- shell/platform/darwin/ios/framework/Source/FlutterView.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterView.mm b/shell/platform/darwin/ios/framework/Source/FlutterView.mm index 892ef38f6e075..f60f114f2ea1c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterView.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterView.mm @@ -79,8 +79,7 @@ + (Class)layerClass { if ([self.layer isKindOfClass:[CAEAGLLayer class]]) { fml::scoped_nsobject eagl_layer( reinterpret_cast([self.layer retain])); - if ([[[NSBundle mainBundle] objectForInfoDictionaryKey:@(shell::kEmbeddedViewsPreview)] - boolValue]) { + if (shell::IsIosEmbeddedViewsPreviewEnabled()) { // TODO(amirh): We can lower this to iOS 8.0 once we have a Metal rendering backend. // https://github.com/flutter/flutter/issues/24132 if (@available(iOS 9.0, *)) {