Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[ios] Surface factory holds the canonical reference to the external view embedder #22206

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions shell/platform/darwin/ios/ios_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class IOSSurface {
static std::unique_ptr<IOSSurface> Create(
std::shared_ptr<IOSContext> context,
fml::scoped_nsobject<CALayer> layer,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller);
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder);

std::shared_ptr<IOSContext> GetContext() const;

Expand All @@ -49,7 +49,7 @@ class IOSSurface {

protected:
IOSSurface(std::shared_ptr<IOSContext> ios_context,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller);
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder);

private:
std::shared_ptr<IOSContext> ios_context_;
Expand Down
22 changes: 9 additions & 13 deletions shell/platform/darwin/ios/ios_surface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
std::unique_ptr<IOSSurface> IOSSurface::Create(
std::shared_ptr<IOSContext> context,
fml::scoped_nsobject<CALayer> layer,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller) {
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder) {
FML_DCHECK(layer);
FML_DCHECK(context);

Expand All @@ -27,7 +27,7 @@
fml::scoped_nsobject<CAEAGLLayer>(
reinterpret_cast<CAEAGLLayer*>([layer.get() retain])), // EAGL layer
std::move(context), // context
platform_views_controller // platform views controller
external_view_embedder // external view embedder
);
}

Expand All @@ -38,26 +38,22 @@
fml::scoped_nsobject<CAMetalLayer>(
reinterpret_cast<CAMetalLayer*>([layer.get() retain])), // Metal layer
std::move(context), // context
platform_views_controller // platform views controller
external_view_embedder // external view embedder
);
}
}
#endif // FLUTTER_SHELL_ENABLE_METAL

return std::make_unique<IOSSurfaceSoftware>(
std::move(layer), // layer
std::move(context), // context
platform_views_controller // platform views controller
return std::make_unique<IOSSurfaceSoftware>(std::move(layer), // layer
std::move(context), // context
external_view_embedder // external view embedder
);
}

IOSSurface::IOSSurface(
std::shared_ptr<IOSContext> ios_context,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller)
: ios_context_(std::move(ios_context)) {
IOSSurface::IOSSurface(std::shared_ptr<IOSContext> ios_context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder)
: ios_context_(std::move(ios_context)), external_view_embedder_(external_view_embedder) {
FML_DCHECK(ios_context_);
external_view_embedder_ =
std::make_shared<IOSExternalViewEmbedder>(platform_views_controller, ios_context_);
}

IOSSurface::~IOSSurface() = default;
Expand Down
5 changes: 4 additions & 1 deletion shell/platform/darwin/ios/ios_surface_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import "flutter/shell/platform/darwin/ios/ios_surface.h"
#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
#include "shell/platform/darwin/ios/ios_external_view_embedder.h"

namespace flutter {

Expand All @@ -28,8 +29,10 @@ class IOSSurfaceFactory {
std::unique_ptr<IOSSurface> CreateSurface(
fml::scoped_nsobject<CALayer> ca_layer);

std::shared_ptr<IOSExternalViewEmbedder> GetExternalViewEmbedder();

private:
std::shared_ptr<FlutterPlatformViewsController> platform_views_controller_;
std::shared_ptr<IOSExternalViewEmbedder> external_view_embedder_;
std::shared_ptr<IOSContext> ios_context_;

FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceFactory);
Expand Down
10 changes: 8 additions & 2 deletions shell/platform/darwin/ios/ios_surface_factory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#import "flutter/shell/platform/darwin/ios/ios_surface_factory.h"
#import "flutter/shell/platform/darwin/ios/ios_context.h"
#include "shell/platform/darwin/ios/ios_external_view_embedder.h"

namespace flutter {

Expand All @@ -19,12 +20,17 @@

void IOSSurfaceFactory::SetPlatformViewsController(
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller) {
platform_views_controller_ = platform_views_controller;
external_view_embedder_.reset(
new IOSExternalViewEmbedder(platform_views_controller, ios_context_));
}

std::shared_ptr<IOSExternalViewEmbedder> IOSSurfaceFactory::GetExternalViewEmbedder() {
return external_view_embedder_;
}

std::unique_ptr<IOSSurface> IOSSurfaceFactory::CreateSurface(
fml::scoped_nsobject<CALayer> ca_layer) {
return flutter::IOSSurface::Create(ios_context_, ca_layer, platform_views_controller_);
return flutter::IOSSurface::Create(ios_context_, ca_layer, external_view_embedder_);
}

} // namespace flutter
7 changes: 3 additions & 4 deletions shell/platform/darwin/ios/ios_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ namespace flutter {

class IOSSurfaceGL final : public IOSSurface, public GPUSurfaceGLDelegate {
public:
IOSSurfaceGL(
fml::scoped_nsobject<CAEAGLLayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller = nullptr);
IOSSurfaceGL(fml::scoped_nsobject<CAEAGLLayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder = nullptr);

~IOSSurfaceGL() override;

Expand Down
9 changes: 4 additions & 5 deletions shell/platform/darwin/ios/ios_surface_gl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
return reinterpret_cast<IOSContextGL*>(context.get());
}

IOSSurfaceGL::IOSSurfaceGL(
fml::scoped_nsobject<CAEAGLLayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller)
: IOSSurface(context, platform_views_controller) {
IOSSurfaceGL::IOSSurfaceGL(fml::scoped_nsobject<CAEAGLLayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder)
: IOSSurface(context, external_view_embedder) {
render_target_ = CastToGLContext(context)->CreateRenderTarget(std::move(layer));
}

Expand Down
2 changes: 1 addition & 1 deletion shell/platform/darwin/ios/ios_surface_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SK_API_AVAILABLE_CA_METAL_LAYER IOSSurfaceMetal final : public IOSSurface,
public:
IOSSurfaceMetal(fml::scoped_nsobject<CAMetalLayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller);
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder);

// |IOSSurface|
~IOSSurfaceMetal() override;
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/darwin/ios/ios_surface_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
IOSSurfaceMetal::IOSSurfaceMetal(
fml::scoped_nsobject<CAMetalLayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller)
: IOSSurface(std::move(context), platform_views_controller), layer_(std::move(layer)) {
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder)
: IOSSurface(std::move(context), external_view_embedder), layer_(std::move(layer)) {
if (!layer_) {
return;
}
Expand Down
7 changes: 3 additions & 4 deletions shell/platform/darwin/ios/ios_surface_software.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ namespace flutter {

class IOSSurfaceSoftware final : public IOSSurface, public GPUSurfaceSoftwareDelegate {
public:
IOSSurfaceSoftware(
fml::scoped_nsobject<CALayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller);
IOSSurfaceSoftware(fml::scoped_nsobject<CALayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder);

~IOSSurfaceSoftware() override;

Expand Down
4 changes: 2 additions & 2 deletions shell/platform/darwin/ios/ios_surface_software.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
IOSSurfaceSoftware::IOSSurfaceSoftware(
fml::scoped_nsobject<CALayer> layer,
std::shared_ptr<IOSContext> context,
const std::shared_ptr<FlutterPlatformViewsController>& platform_views_controller)
: IOSSurface(std::move(context), platform_views_controller), layer_(std::move(layer)) {}
const std::shared_ptr<IOSExternalViewEmbedder>& external_view_embedder)
: IOSSurface(std::move(context), external_view_embedder), layer_(std::move(layer)) {}

IOSSurfaceSoftware::~IOSSurfaceSoftware() = default;

Expand Down