Skip to content

Commit df85722

Browse files
authored
Plumb the iOS PlatformViewsController into flow. (flutter#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.
1 parent 2bfb893 commit df85722

27 files changed

+178
-23
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ORIGIN: ../../../flutter/flow/layers/physical_shape_layer.cc + ../../../LICENSE
1111
TYPE: LicenseType.bsd
1212
FILE: ../../../flutter/flow/debug_print.cc
1313
FILE: ../../../flutter/flow/debug_print.h
14+
FILE: ../../../flutter/flow/embedded_views.h
1415
FILE: ../../../flutter/flow/export_node.h
1516
FILE: ../../../flutter/flow/layers/physical_shape_layer.cc
1617
FILE: ../../../flutter/flow/layers/physical_shape_layer.h

flow/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ source_set("flow") {
88
"compositor_context.h",
99
"debug_print.cc",
1010
"debug_print.h",
11+
"embedded_views.h",
1112
"instrumentation.cc",
1213
"instrumentation.h",
1314
"layers/backdrop_filter_layer.cc",

flow/compositor_context.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,25 @@ void CompositorContext::EndFrame(ScopedFrame& frame,
3232
std::unique_ptr<CompositorContext::ScopedFrame> CompositorContext::AcquireFrame(
3333
GrContext* gr_context,
3434
SkCanvas* canvas,
35+
ExternalViewEmbedder* view_embedder,
3536
const SkMatrix& root_surface_transformation,
3637
bool instrumentation_enabled) {
37-
return std::make_unique<ScopedFrame>(*this, //
38-
gr_context, //
39-
canvas, //
40-
root_surface_transformation, //
41-
instrumentation_enabled //
42-
);
38+
return std::make_unique<ScopedFrame>(*this, gr_context, canvas, view_embedder,
39+
root_surface_transformation,
40+
instrumentation_enabled);
4341
}
4442

4543
CompositorContext::ScopedFrame::ScopedFrame(
4644
CompositorContext& context,
4745
GrContext* gr_context,
4846
SkCanvas* canvas,
47+
ExternalViewEmbedder* view_embedder,
4948
const SkMatrix& root_surface_transformation,
5049
bool instrumentation_enabled)
5150
: context_(context),
5251
gr_context_(gr_context),
5352
canvas_(canvas),
53+
view_embedder_(view_embedder),
5454
root_surface_transformation_(root_surface_transformation),
5555
instrumentation_enabled_(instrumentation_enabled) {
5656
context_.BeginFrame(*this, instrumentation_enabled_);

flow/compositor_context.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <memory>
99
#include <string>
1010

11+
#include "flutter/flow/embedded_views.h"
1112
#include "flutter/flow/instrumentation.h"
1213
#include "flutter/flow/raster_cache.h"
1314
#include "flutter/flow/texture.h"
@@ -26,13 +27,16 @@ class CompositorContext {
2627
ScopedFrame(CompositorContext& context,
2728
GrContext* gr_context,
2829
SkCanvas* canvas,
30+
ExternalViewEmbedder* view_embedder,
2931
const SkMatrix& root_surface_transformation,
3032
bool instrumentation_enabled);
3133

3234
virtual ~ScopedFrame();
3335

3436
SkCanvas* canvas() { return canvas_; }
3537

38+
ExternalViewEmbedder* view_embedder() { return view_embedder_; }
39+
3640
CompositorContext& context() const { return context_; }
3741

3842
const SkMatrix& root_surface_transformation() const {
@@ -47,6 +51,7 @@ class CompositorContext {
4751
CompositorContext& context_;
4852
GrContext* gr_context_;
4953
SkCanvas* canvas_;
54+
ExternalViewEmbedder* view_embedder_;
5055
const SkMatrix& root_surface_transformation_;
5156
const bool instrumentation_enabled_;
5257

@@ -60,6 +65,7 @@ class CompositorContext {
6065
virtual std::unique_ptr<ScopedFrame> AcquireFrame(
6166
GrContext* gr_context,
6267
SkCanvas* canvas,
68+
ExternalViewEmbedder* view_embedder,
6369
const SkMatrix& root_surface_transformation,
6470
bool instrumentation_enabled);
6571

flow/embedded_views.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2017 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
//
5+
#ifndef FLUTTER_FLOW_EMBEDDED_VIEWS_H_
6+
#define FLUTTER_FLOW_EMBEDDED_VIEWS_H_
7+
8+
#include "flutter/fml/memory/ref_counted.h"
9+
10+
namespace flow {
11+
12+
class EmbeddedViewParams {
13+
public:
14+
};
15+
16+
// This is only used on iOS when running in a non headless mode,
17+
// in this case ViewEmbedded is a reference to the
18+
// FlutterPlatformViewsController which is owned by FlutterViewController.
19+
class ExternalViewEmbedder {
20+
public:
21+
ExternalViewEmbedder() = default;
22+
23+
// Must be called on the UI thread.
24+
virtual void CompositeEmbeddedView(int view_id,
25+
const EmbeddedViewParams& params) {}
26+
27+
virtual ~ExternalViewEmbedder() = default;
28+
29+
FML_DISALLOW_COPY_AND_ASSIGN(ExternalViewEmbedder);
30+
};
31+
32+
} // namespace flow
33+
34+
#endif // FLUTTER_FLOW_EMBEDDED_VIEWS_H_

flow/layers/layer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <memory>
99
#include <vector>
1010

11+
#include "flutter/flow/embedded_views.h"
1112
#include "flutter/flow/instrumentation.h"
1213
#include "flutter/flow/raster_cache.h"
1314
#include "flutter/flow/texture.h"
@@ -64,6 +65,7 @@ class Layer {
6465

6566
struct PaintContext {
6667
SkCanvas& canvas;
68+
ExternalViewEmbedder* view_embedder;
6769
const Stopwatch& frame_time;
6870
const Stopwatch& engine_time;
6971
TextureRegistry& texture_registry;

flow/layers/layer_tree.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void LayerTree::Paint(CompositorContext::ScopedFrame& frame,
6868
TRACE_EVENT0("flutter", "LayerTree::Paint");
6969
Layer::PaintContext context = {
7070
*frame.canvas(),
71+
frame.view_embedder(),
7172
frame.context().frame_time(),
7273
frame.context().engine_time(),
7374
frame.context().texture_registry(),
@@ -106,7 +107,8 @@ sk_sp<SkPicture> LayerTree::Flatten(const SkRect& bounds) {
106107
};
107108

108109
Layer::PaintContext paint_context = {
109-
*canvas, // canvas
110+
*canvas, // canvas
111+
nullptr,
110112
unused_stopwatch, // frame time (dont care)
111113
unused_stopwatch, // engine time (dont care)
112114
unused_texture_registry, // texture registry (not supported)

flow/layers/platform_view_layer.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ void PlatformViewLayer::Preroll(PrerollContext* context,
1616
size_.height()));
1717
}
1818

19-
void PlatformViewLayer::Paint(PaintContext& context) const {}
20-
19+
void PlatformViewLayer::Paint(PaintContext& context) const {
20+
if (context.view_embedder == nullptr) {
21+
FML_LOG(ERROR) << "Trying to embed a platform view but the PaintContext "
22+
"does not support embedding";
23+
return;
24+
}
25+
EmbeddedViewParams params;
26+
context.view_embedder->CompositeEmbeddedView(view_id_, params);
27+
}
2128
} // namespace flow

flow/raster_cache.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void RasterCache::Prepare(PrerollContext* context,
158158
[layer, context](SkCanvas* canvas) {
159159
Layer::PaintContext paintContext = {
160160
*canvas,
161+
nullptr,
161162
context->frame_time,
162163
context->engine_time,
163164
context->texture_registry,

shell/common/rasterizer.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ bool Rasterizer::DrawToSurface(flow::LayerTree& layer_tree) {
167167
auto canvas = frame->SkiaCanvas();
168168

169169
auto compositor_frame = compositor_context_->AcquireFrame(
170-
surface_->GetContext(), canvas, surface_->GetRootTransformation(), true);
170+
surface_->GetContext(), canvas, surface_->GetExternalViewEmbedder(),
171+
surface_->GetRootTransformation(), true);
171172

172173
if (canvas) {
173174
canvas->clear(SK_ColorTRANSPARENT);
@@ -197,9 +198,11 @@ static sk_sp<SkData> ScreenshotLayerTreeAsPicture(
197198
SkMatrix root_surface_transformation;
198199
root_surface_transformation.reset();
199200

200-
auto frame =
201-
compositor_context.AcquireFrame(nullptr, recorder.getRecordingCanvas(),
202-
root_surface_transformation, false);
201+
// TODO(amirh): figure out how to take a screenshot with embedded UIView.
202+
// https://github.com/flutter/flutter/issues/23435
203+
auto frame = compositor_context.AcquireFrame(
204+
nullptr, recorder.getRecordingCanvas(), nullptr,
205+
root_surface_transformation, false);
203206

204207
frame->Raster(*tree, true);
205208

@@ -249,7 +252,7 @@ static sk_sp<SkData> ScreenshotLayerTreeAsImage(
249252
root_surface_transformation.reset();
250253

251254
auto frame = compositor_context.AcquireFrame(
252-
surface_context, canvas, root_surface_transformation, false);
255+
surface_context, canvas, nullptr, root_surface_transformation, false);
253256
canvas->clear(SK_ColorTRANSPARENT);
254257
frame->Raster(*tree, true);
255258
canvas->flush();

0 commit comments

Comments
 (0)