Skip to content

Commit

Permalink
Synchronize Flutter's rendering with CA.
Browse files Browse the repository at this point in the history
Right now we do it whenever the platform views preview flag is on.
This is less efficient, filed
flutter/flutter#24133 to only do this when
there's a platform view in the tree.
  • Loading branch information
Amir Hardon committed Nov 9, 2018
1 parent f5e5d81 commit 13453c8
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion flow/embedded_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion shell/common/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ + (Class)layerClass {
- (std::unique_ptr<shell::IOSSurfaceGL>)createGLSurfaceWithContext:
(std::shared_ptr<shell::IOSGLContext>)gl_context {
fml::scoped_nsobject<CAEAGLLayer> eagl_layer(reinterpret_cast<CAEAGLLayer*>([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<shell::IOSSurfaceGL>(eagl_layer, std::move(gl_context));
}

Expand Down
10 changes: 10 additions & 0 deletions shell/platform/darwin/ios/framework/Source/FlutterView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ + (Class)layerClass {
if ([self.layer isKindOfClass:[CAEAGLLayer class]]) {
fml::scoped_nsobject<CAEAGLLayer> eagl_layer(
reinterpret_cast<CAEAGLLayer*>([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<shell::IOSSurfaceGL>(std::move(eagl_layer),
[_delegate platformViewsController]);
} else {
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/darwin/ios/ios_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions shell/platform/darwin/ios/ios_surface_gl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
2 changes: 1 addition & 1 deletion shell/platform/darwin/ios/ios_surface_software.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/darwin/ios/ios_surface_software.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 13453c8

Please sign in to comment.