Revert "Manage resource and onscreen contexts using separate IOSGLContext objects (#11798)" (flutter/engine#12055)

This reverts commit 9297908d54.
This commit is contained in:
Kaushik Iska
2019-09-06 18:12:16 -07:00
committed by GitHub
parent 9297908d54
commit 2d656f6f32
19 changed files with 79 additions and 199 deletions

View File

@@ -36,8 +36,6 @@
- (fml::WeakPtr<flutter::PlatformView>)platformView; - (fml::WeakPtr<flutter::PlatformView>)platformView;
- (flutter::PlatformViewIOS*)iosPlatformView;
- (flutter::Rasterizer::Screenshot)screenshot:(flutter::Rasterizer::ScreenshotType)type - (flutter::Rasterizer::Screenshot)screenshot:(flutter::Rasterizer::ScreenshotType)type
base64Encode:(bool)base64Encode; base64Encode:(bool)base64Encode;

View File

@@ -24,9 +24,8 @@
- (instancetype)init NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithContentsScale:(CGFloat)contentsScale; - (instancetype)initWithContentsScale:(CGFloat)contentsScale;
- (std::unique_ptr<flutter::IOSSurface>) - (std::unique_ptr<flutter::IOSSurface>)createSurface:
createSurfaceWithOnscreenGLContext:(fml::WeakPtr<flutter::IOSGLContext>)onscreenGLContext (std::shared_ptr<flutter::IOSGLContext>)gl_context;
resourceGLContext:(fml::WeakPtr<flutter::IOSGLContext>)resourceGLContext;
@end @end

View File

@@ -78,17 +78,15 @@
#endif // TARGET_IPHONE_SIMULATOR #endif // TARGET_IPHONE_SIMULATOR
} }
- (std::unique_ptr<flutter::IOSSurface>) - (std::unique_ptr<flutter::IOSSurface>)createSurface:
createSurfaceWithOnscreenGLContext:(fml::WeakPtr<flutter::IOSGLContext>)onscreenGLContext (std::shared_ptr<flutter::IOSGLContext>)gl_context {
resourceGLContext:(fml::WeakPtr<flutter::IOSGLContext>)resourceGLContext {
if ([self.layer isKindOfClass:[CAEAGLLayer class]]) { if ([self.layer isKindOfClass:[CAEAGLLayer class]]) {
fml::scoped_nsobject<CAEAGLLayer> eagl_layer( fml::scoped_nsobject<CAEAGLLayer> eagl_layer(
reinterpret_cast<CAEAGLLayer*>([self.layer retain])); reinterpret_cast<CAEAGLLayer*>([self.layer retain]));
if (@available(iOS 9.0, *)) { if (@available(iOS 9.0, *)) {
eagl_layer.get().presentsWithTransaction = YES; eagl_layer.get().presentsWithTransaction = YES;
} }
return std::make_unique<flutter::IOSSurfaceGL>(std::move(eagl_layer), onscreenGLContext, return std::make_unique<flutter::IOSSurfaceGL>(std::move(eagl_layer), gl_context);
resourceGLContext);
#if FLUTTER_SHELL_ENABLE_METAL #if FLUTTER_SHELL_ENABLE_METAL
} else if ([self.layer isKindOfClass:[CAMetalLayer class]]) { } else if ([self.layer isKindOfClass:[CAMetalLayer class]]) {
fml::scoped_nsobject<CAMetalLayer> metalLayer( fml::scoped_nsobject<CAMetalLayer> metalLayer(

View File

@@ -362,13 +362,12 @@ void FlutterPlatformViewsController::Reset() {
} }
bool FlutterPlatformViewsController::SubmitFrame(GrContext* gr_context, bool FlutterPlatformViewsController::SubmitFrame(GrContext* gr_context,
fml::WeakPtr<IOSGLContext> onscreen_gl_context, std::shared_ptr<IOSGLContext> gl_context) {
fml::WeakPtr<IOSGLContext> resource_gl_context) {
DisposeViews(); DisposeViews();
bool did_submit = true; bool did_submit = true;
for (int64_t view_id : composition_order_) { for (int64_t view_id : composition_order_) {
EnsureOverlayInitialized(view_id, onscreen_gl_context, resource_gl_context, gr_context); EnsureOverlayInitialized(view_id, std::move(gl_context), gr_context);
auto frame = overlays_[view_id]->surface->AcquireFrame(frame_size_); auto frame = overlays_[view_id]->surface->AcquireFrame(frame_size_);
SkCanvas* canvas = frame->SkiaCanvas(); SkCanvas* canvas = frame->SkiaCanvas();
canvas->drawPicture(picture_recorders_[view_id]->finishRecordingAsPicture()); canvas->drawPicture(picture_recorders_[view_id]->finishRecordingAsPicture());
@@ -452,8 +451,7 @@ void FlutterPlatformViewsController::DisposeViews() {
void FlutterPlatformViewsController::EnsureOverlayInitialized( void FlutterPlatformViewsController::EnsureOverlayInitialized(
int64_t overlay_id, int64_t overlay_id,
fml::WeakPtr<IOSGLContext> onscreen_gl_context, std::shared_ptr<IOSGLContext> gl_context,
fml::WeakPtr<IOSGLContext> resource_gl_context,
GrContext* gr_context) { GrContext* gr_context) {
FML_DCHECK(flutter_view_); FML_DCHECK(flutter_view_);
@@ -469,9 +467,7 @@ void FlutterPlatformViewsController::EnsureOverlayInitialized(
overlay_view.get().frame = flutter_view_.get().bounds; overlay_view.get().frame = flutter_view_.get().bounds;
overlay_view.get().autoresizingMask = overlay_view.get().autoresizingMask =
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
std::unique_ptr<IOSSurface> ios_surface = [overlay_view.get() std::unique_ptr<IOSSurface> ios_surface = [overlay_view.get() createSurface:nil];
createSurfaceWithOnscreenGLContext:fml::WeakPtr<flutter::IOSGLContext>()
resourceGLContext:fml::WeakPtr<flutter::IOSGLContext>()];
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(); std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface();
overlays_[overlay_id] = std::make_unique<FlutterPlatformViewLayer>( overlays_[overlay_id] = std::make_unique<FlutterPlatformViewLayer>(
std::move(overlay_view), std::move(ios_surface), std::move(surface)); std::move(overlay_view), std::move(ios_surface), std::move(surface));
@@ -496,8 +492,7 @@ void FlutterPlatformViewsController::EnsureOverlayInitialized(
overlay_view.get().autoresizingMask = overlay_view.get().autoresizingMask =
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
std::unique_ptr<IOSSurface> ios_surface = std::unique_ptr<IOSSurface> ios_surface =
[overlay_view.get() createSurfaceWithOnscreenGLContext:std::move(onscreen_gl_context) [overlay_view.get() createSurface:std::move(gl_context)];
resourceGLContext:std::move(resource_gl_context)];
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context); std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context);
overlays_[overlay_id] = std::make_unique<FlutterPlatformViewLayer>( overlays_[overlay_id] = std::make_unique<FlutterPlatformViewLayer>(
std::move(overlay_view), std::move(ios_surface), std::move(surface)); std::move(overlay_view), std::move(ios_surface), std::move(surface));

View File

@@ -100,9 +100,7 @@ class FlutterPlatformViewsController {
// Discards all platform views instances and auxiliary resources. // Discards all platform views instances and auxiliary resources.
void Reset(); void Reset();
bool SubmitFrame(GrContext* gr_context, bool SubmitFrame(GrContext* gr_context, std::shared_ptr<IOSGLContext> gl_context);
fml::WeakPtr<IOSGLContext> onscreen_gl_context,
fml::WeakPtr<IOSGLContext> resource_gl_context);
void OnMethodCall(FlutterMethodCall* call, FlutterResult& result); void OnMethodCall(FlutterMethodCall* call, FlutterResult& result);
@@ -164,8 +162,7 @@ class FlutterPlatformViewsController {
// Dispose the views in `views_to_dispose_`. // Dispose the views in `views_to_dispose_`.
void DisposeViews(); void DisposeViews();
void EnsureOverlayInitialized(int64_t overlay_id, void EnsureOverlayInitialized(int64_t overlay_id,
fml::WeakPtr<IOSGLContext> onscreen_gl_context, std::shared_ptr<IOSGLContext> gl_context,
fml::WeakPtr<IOSGLContext> resource_gl_context,
GrContext* gr_context); GrContext* gr_context);
// This will return true after pre-roll if any of the embedded views // This will return true after pre-roll if any of the embedded views

View File

@@ -33,8 +33,8 @@
- (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate - (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate
opaque:(BOOL)opaque NS_DESIGNATED_INITIALIZER; opaque:(BOOL)opaque NS_DESIGNATED_INITIALIZER;
- (std::unique_ptr<flutter::IOSSurface>)createSurfaceWithResourceGLContext: - (std::unique_ptr<flutter::IOSSurface>)createSurface:
(fml::WeakPtr<flutter::IOSGLContext>)resourceGLContext; (std::shared_ptr<flutter::IOSGLContext>)context;
@end @end

View File

@@ -13,7 +13,6 @@
#include "flutter/shell/common/platform_view.h" #include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/rasterizer.h" #include "flutter/shell/common/rasterizer.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h" #include "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
#include "flutter/shell/platform/darwin/ios/ios_gl_context.h"
#include "flutter/shell/platform/darwin/ios/ios_surface_gl.h" #include "flutter/shell/platform/darwin/ios/ios_surface_gl.h"
#include "flutter/shell/platform/darwin/ios/ios_surface_software.h" #include "flutter/shell/platform/darwin/ios/ios_surface_software.h"
#include "third_party/skia/include/utils/mac/SkCGUtils.h" #include "third_party/skia/include/utils/mac/SkCGUtils.h"
@@ -22,10 +21,9 @@
#include "flutter/shell/platform/darwin/ios/ios_surface_metal.h" #include "flutter/shell/platform/darwin/ios/ios_surface_metal.h"
#endif // FLUTTER_SHELL_ENABLE_METAL #endif // FLUTTER_SHELL_ENABLE_METAL
@implementation FlutterView { @implementation FlutterView
id<FlutterViewEngineDelegate> _delegate;
std::unique_ptr<flutter::IOSGLContext> _onscreenGLContext; id<FlutterViewEngineDelegate> _delegate;
}
- (instancetype)init { - (instancetype)init {
@throw([NSException exceptionWithName:@"FlutterView must initWithDelegate" @throw([NSException exceptionWithName:@"FlutterView must initWithDelegate"
@@ -95,14 +93,8 @@
#endif // TARGET_IPHONE_SIMULATOR #endif // TARGET_IPHONE_SIMULATOR
} }
- (std::unique_ptr<flutter::IOSSurface>)createSurfaceWithResourceGLContext: - (std::unique_ptr<flutter::IOSSurface>)createSurface:
(fml::WeakPtr<flutter::IOSGLContext>)resourceGLContext { (std::shared_ptr<flutter::IOSGLContext>)context {
#if !TARGET_IPHONE_SIMULATOR
if (!_onscreenGLContext) {
_onscreenGLContext = resourceGLContext->MakeSharedContext();
}
#endif // !TARGET_IPHONE_SIMULATOR
if ([self.layer isKindOfClass:[CAEAGLLayer class]]) { if ([self.layer isKindOfClass:[CAEAGLLayer class]]) {
fml::scoped_nsobject<CAEAGLLayer> eagl_layer( fml::scoped_nsobject<CAEAGLLayer> eagl_layer(
reinterpret_cast<CAEAGLLayer*>([self.layer retain])); reinterpret_cast<CAEAGLLayer*>([self.layer retain]));
@@ -113,9 +105,8 @@
eagl_layer.get().presentsWithTransaction = YES; eagl_layer.get().presentsWithTransaction = YES;
} }
} }
return std::make_unique<flutter::IOSSurfaceGL>( return std::make_unique<flutter::IOSSurfaceGL>(context, std::move(eagl_layer),
_onscreenGLContext->GetWeakPtr(), std::move(resourceGLContext), std::move(eagl_layer), [_delegate platformViewsController]);
[_delegate platformViewsController]);
#if FLUTTER_SHELL_ENABLE_METAL #if FLUTTER_SHELL_ENABLE_METAL
} else if ([self.layer isKindOfClass:[CAMetalLayer class]]) { } else if ([self.layer isKindOfClass:[CAMetalLayer class]]) {
fml::scoped_nsobject<CAMetalLayer> metalLayer( fml::scoped_nsobject<CAMetalLayer> metalLayer(

View File

@@ -1152,8 +1152,4 @@ constexpr CGFloat kStandardStatusBarHeight = 20.0;
return [_engine.get() valuePublishedByPlugin:pluginKey]; return [_engine.get() valuePublishedByPlugin:pluginKey];
} }
- (BOOL)hasOnscreenSurface {
return [_engine.get() iosPlatformView] -> HasOnscreenSurface();
}
@end @end

View File

@@ -13,32 +13,30 @@
#include "flutter/fml/macros.h" #include "flutter/fml/macros.h"
#include "flutter/fml/platform/darwin/scoped_nsobject.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h"
#include "flutter/shell/common/platform_view.h" #include "flutter/shell/common/platform_view.h"
#include "ios_gl_render_target.h"
namespace flutter { namespace flutter {
class IOSGLContext { class IOSGLContext {
public: public:
IOSGLContext(); IOSGLContext();
IOSGLContext(EAGLSharegroup* sharegroup);
~IOSGLContext(); ~IOSGLContext();
std::unique_ptr<IOSGLRenderTarget> CreateRenderTarget(
fml::scoped_nsobject<CAEAGLLayer> layer);
bool MakeCurrent(); bool MakeCurrent();
bool BindRenderbufferStorage(fml::scoped_nsobject<CAEAGLLayer> layer); bool ResourceMakeCurrent();
sk_sp<SkColorSpace> ColorSpace() const { return color_space_; } sk_sp<SkColorSpace> ColorSpace() const { return color_space_; }
std::unique_ptr<IOSGLContext> MakeSharedContext();
fml::WeakPtr<IOSGLContext> GetWeakPtr();
private: private:
fml::scoped_nsobject<EAGLContext> context_; fml::scoped_nsobject<EAGLContext> context_;
fml::scoped_nsobject<EAGLContext> resource_context_;
sk_sp<SkColorSpace> color_space_; sk_sp<SkColorSpace> color_space_;
std::unique_ptr<fml::WeakPtrFactory<IOSGLContext>> weak_factory_;
FML_DISALLOW_COPY_AND_ASSIGN(IOSGLContext); FML_DISALLOW_COPY_AND_ASSIGN(IOSGLContext);
}; };

View File

@@ -12,16 +12,15 @@
namespace flutter { namespace flutter {
IOSGLContext::IOSGLContext() : IOSGLContext(nullptr) {} IOSGLContext::IOSGLContext() {
resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]);
IOSGLContext::IOSGLContext(EAGLSharegroup* sharegroup) if (resource_context_ != nullptr) {
: weak_factory_(std::make_unique<fml::WeakPtrFactory<IOSGLContext>>(this)) { context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3
context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3 sharegroup:resource_context_.get().sharegroup]);
sharegroup:sharegroup]); } else {
resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]);
if (!context_) {
context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2
sharegroup:sharegroup]); sharegroup:resource_context_.get().sharegroup]);
} }
// TODO: // TODO:
@@ -45,22 +44,20 @@ IOSGLContext::IOSGLContext(EAGLSharegroup* sharegroup)
} }
} }
fml::WeakPtr<IOSGLContext> IOSGLContext::GetWeakPtr() {
return weak_factory_->GetWeakPtr();
}
bool IOSGLContext::BindRenderbufferStorage(fml::scoped_nsobject<CAEAGLLayer> layer) {
return [context_.get() renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer.get()];
}
IOSGLContext::~IOSGLContext() = default; IOSGLContext::~IOSGLContext() = default;
std::unique_ptr<IOSGLRenderTarget> IOSGLContext::CreateRenderTarget(
fml::scoped_nsobject<CAEAGLLayer> layer) {
return std::make_unique<IOSGLRenderTarget>(std::move(layer), context_.get(),
resource_context_.get());
}
bool IOSGLContext::MakeCurrent() { bool IOSGLContext::MakeCurrent() {
return [EAGLContext setCurrentContext:context_.get()]; return [EAGLContext setCurrentContext:context_.get()];
} }
std::unique_ptr<IOSGLContext> IOSGLContext::MakeSharedContext() { bool IOSGLContext::ResourceMakeCurrent() {
return std::make_unique<IOSGLContext>(context_.get().sharegroup); return [EAGLContext setCurrentContext:resource_context_.get()];
} }
} // namespace flutter } // namespace flutter

View File

@@ -13,15 +13,14 @@
#include "flutter/fml/macros.h" #include "flutter/fml/macros.h"
#include "flutter/fml/platform/darwin/scoped_nsobject.h" #include "flutter/fml/platform/darwin/scoped_nsobject.h"
#include "flutter/shell/common/platform_view.h" #include "flutter/shell/common/platform_view.h"
#include "flutter/shell/platform/darwin/ios/ios_gl_context.h"
namespace flutter { namespace flutter {
class IOSGLRenderTarget { class IOSGLRenderTarget {
public: public:
IOSGLRenderTarget(fml::scoped_nsobject<CAEAGLLayer> layer, IOSGLRenderTarget(fml::scoped_nsobject<CAEAGLLayer> layer,
fml::WeakPtr<IOSGLContext> onscreen_context, EAGLContext* context,
fml::WeakPtr<IOSGLContext> resource_context); EAGLContext* resource_context);
~IOSGLRenderTarget(); ~IOSGLRenderTarget();
@@ -41,8 +40,8 @@ class IOSGLRenderTarget {
private: private:
fml::scoped_nsobject<CAEAGLLayer> layer_; fml::scoped_nsobject<CAEAGLLayer> layer_;
fml::WeakPtr<IOSGLContext> onscreen_gl_context_; fml::scoped_nsobject<EAGLContext> context_;
fml::WeakPtr<IOSGLContext> resource_gl_context_; fml::scoped_nsobject<EAGLContext> resource_context_;
GLuint framebuffer_; GLuint framebuffer_;
GLuint colorbuffer_; GLuint colorbuffer_;
GLint storage_size_width_; GLint storage_size_width_;

View File

@@ -11,22 +11,23 @@
#include "third_party/skia/include/gpu/gl/GrGLInterface.h" #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
namespace flutter { namespace flutter {
IOSGLRenderTarget::IOSGLRenderTarget(fml::scoped_nsobject<CAEAGLLayer> layer, IOSGLRenderTarget::IOSGLRenderTarget(fml::scoped_nsobject<CAEAGLLayer> layer,
fml::WeakPtr<IOSGLContext> onscreen_gl_context, EAGLContext* context,
fml::WeakPtr<IOSGLContext> resource_gl_context) EAGLContext* resource_context)
: layer_(std::move(layer)), : layer_(std::move(layer)),
onscreen_gl_context_(std::move(onscreen_gl_context)), context_([context retain]),
resource_gl_context_(std::move(resource_gl_context)), resource_context_([resource_context retain]),
framebuffer_(GL_NONE), framebuffer_(GL_NONE),
colorbuffer_(GL_NONE), colorbuffer_(GL_NONE),
storage_size_width_(0), storage_size_width_(0),
storage_size_height_(0), storage_size_height_(0),
valid_(false) { valid_(false) {
FML_DCHECK(layer_ != nullptr); FML_DCHECK(layer_ != nullptr);
FML_DCHECK(onscreen_gl_context_); FML_DCHECK(context_ != nullptr);
FML_DCHECK(resource_gl_context_); FML_DCHECK(resource_context_ != nullptr);
bool context_current = onscreen_gl_context_->MakeCurrent(); bool context_current = [EAGLContext setCurrentContext:context_];
FML_DCHECK(context_current); FML_DCHECK(context_current);
FML_DCHECK(glGetError() == GL_NO_ERROR); FML_DCHECK(glGetError() == GL_NO_ERROR);
@@ -62,7 +63,7 @@ IOSGLRenderTarget::IOSGLRenderTarget(fml::scoped_nsobject<CAEAGLLayer> layer,
IOSGLRenderTarget::~IOSGLRenderTarget() { IOSGLRenderTarget::~IOSGLRenderTarget() {
EAGLContext* context = EAGLContext.currentContext; EAGLContext* context = EAGLContext.currentContext;
onscreen_gl_context_->MakeCurrent(); [EAGLContext setCurrentContext:context_];
FML_DCHECK(glGetError() == GL_NO_ERROR); FML_DCHECK(glGetError() == GL_NO_ERROR);
// Deletes on GL_NONEs are ignored // Deletes on GL_NONEs are ignored
@@ -104,7 +105,7 @@ bool IOSGLRenderTarget::UpdateStorageSizeIfNecessary() {
FML_DCHECK(glGetError() == GL_NO_ERROR); FML_DCHECK(glGetError() == GL_NO_ERROR);
if (!onscreen_gl_context_->MakeCurrent()) { if (![EAGLContext setCurrentContext:context_]) {
return false; return false;
} }
@@ -115,7 +116,7 @@ bool IOSGLRenderTarget::UpdateStorageSizeIfNecessary() {
glBindRenderbuffer(GL_RENDERBUFFER, colorbuffer_); glBindRenderbuffer(GL_RENDERBUFFER, colorbuffer_);
FML_DCHECK(glGetError() == GL_NO_ERROR); FML_DCHECK(glGetError() == GL_NO_ERROR);
if (!onscreen_gl_context_->BindRenderbufferStorage(layer_)) { if (![context_.get() renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer_.get()]) {
return false; return false;
} }
@@ -132,11 +133,11 @@ bool IOSGLRenderTarget::UpdateStorageSizeIfNecessary() {
} }
bool IOSGLRenderTarget::MakeCurrent() { bool IOSGLRenderTarget::MakeCurrent() {
return UpdateStorageSizeIfNecessary() && onscreen_gl_context_->MakeCurrent(); return UpdateStorageSizeIfNecessary() && [EAGLContext setCurrentContext:context_.get()];
} }
bool IOSGLRenderTarget::ResourceMakeCurrent() { bool IOSGLRenderTarget::ResourceMakeCurrent() {
return resource_gl_context_->MakeCurrent(); return [EAGLContext setCurrentContext:resource_context_.get()];
} }
} // namespace flutter } // namespace flutter

View File

@@ -20,14 +20,11 @@ class IOSSurfaceGL final : public IOSSurface,
public GPUSurfaceGLDelegate, public GPUSurfaceGLDelegate,
public ExternalViewEmbedder { public ExternalViewEmbedder {
public: public:
IOSSurfaceGL(fml::WeakPtr<IOSGLContext> onscreen_gl_context, IOSSurfaceGL(std::shared_ptr<IOSGLContext> context,
fml::WeakPtr<IOSGLContext> resource_gl_context,
fml::scoped_nsobject<CAEAGLLayer> layer, fml::scoped_nsobject<CAEAGLLayer> layer,
FlutterPlatformViewsController* platform_views_controller); FlutterPlatformViewsController* platform_views_controller);
IOSSurfaceGL(fml::scoped_nsobject<CAEAGLLayer> layer, IOSSurfaceGL(fml::scoped_nsobject<CAEAGLLayer> layer, std::shared_ptr<IOSGLContext> context);
fml::WeakPtr<IOSGLContext> onscreen_gl_context,
fml::WeakPtr<IOSGLContext> resource_gl_context);
~IOSSurfaceGL() override; ~IOSSurfaceGL() override;
@@ -82,10 +79,7 @@ class IOSSurfaceGL final : public IOSSurface,
bool SubmitFrame(GrContext* context) override; bool SubmitFrame(GrContext* context) override;
private: private:
fml::WeakPtr<IOSGLContext> onscreen_gl_context_; std::shared_ptr<IOSGLContext> context_;
fml::WeakPtr<IOSGLContext> resource_gl_context_;
std::unique_ptr<IOSGLRenderTarget> render_target_; std::unique_ptr<IOSGLRenderTarget> render_target_;
FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceGL); FML_DISALLOW_COPY_AND_ASSIGN(IOSSurfaceGL);

View File

@@ -9,25 +9,17 @@
namespace flutter { namespace flutter {
IOSSurfaceGL::IOSSurfaceGL(fml::WeakPtr<IOSGLContext> onscreen_gl_context, IOSSurfaceGL::IOSSurfaceGL(std::shared_ptr<IOSGLContext> context,
fml::WeakPtr<IOSGLContext> resource_gl_context,
fml::scoped_nsobject<CAEAGLLayer> layer, fml::scoped_nsobject<CAEAGLLayer> layer,
FlutterPlatformViewsController* platform_views_controller) FlutterPlatformViewsController* platform_views_controller)
: IOSSurface(platform_views_controller), : IOSSurface(platform_views_controller), context_(context) {
onscreen_gl_context_(std::move(onscreen_gl_context)), render_target_ = context_->CreateRenderTarget(std::move(layer));
resource_gl_context_(std::move(resource_gl_context)) {
render_target_ = std::make_unique<IOSGLRenderTarget>(std::move(layer), onscreen_gl_context_,
resource_gl_context_);
} }
IOSSurfaceGL::IOSSurfaceGL(fml::scoped_nsobject<CAEAGLLayer> layer, IOSSurfaceGL::IOSSurfaceGL(fml::scoped_nsobject<CAEAGLLayer> layer,
fml::WeakPtr<IOSGLContext> onscreen_gl_context, std::shared_ptr<IOSGLContext> context)
fml::WeakPtr<IOSGLContext> resource_gl_context) : IOSSurface(nullptr), context_(context) {
: IOSSurface(nullptr), render_target_ = context_->CreateRenderTarget(std::move(layer));
onscreen_gl_context_(std::move(onscreen_gl_context)),
resource_gl_context_(std::move(resource_gl_context)) {
render_target_ = std::make_unique<IOSGLRenderTarget>(std::move(layer), onscreen_gl_context_,
resource_gl_context_);
} }
IOSSurfaceGL::~IOSSurfaceGL() = default; IOSSurfaceGL::~IOSSurfaceGL() = default;
@@ -37,7 +29,7 @@ bool IOSSurfaceGL::IsValid() const {
} }
bool IOSSurfaceGL::ResourceContextMakeCurrent() { bool IOSSurfaceGL::ResourceContextMakeCurrent() {
return resource_gl_context_->MakeCurrent(); return context_->ResourceMakeCurrent();
} }
void IOSSurfaceGL::UpdateStorageSizeIfNecessary() { void IOSSurfaceGL::UpdateStorageSizeIfNecessary() {
@@ -68,7 +60,7 @@ bool IOSSurfaceGL::GLContextMakeCurrent() {
if (!IsValid()) { if (!IsValid()) {
return false; return false;
} }
return render_target_->UpdateStorageSizeIfNecessary() && onscreen_gl_context_->MakeCurrent(); return render_target_->UpdateStorageSizeIfNecessary() && context_->MakeCurrent();
} }
bool IOSSurfaceGL::GLContextClearCurrent() { bool IOSSurfaceGL::GLContextClearCurrent() {
@@ -153,8 +145,7 @@ bool IOSSurfaceGL::SubmitFrame(GrContext* context) {
return true; return true;
} }
bool submitted = platform_views_controller->SubmitFrame(std::move(context), onscreen_gl_context_, bool submitted = platform_views_controller->SubmitFrame(std::move(context), context_);
resource_gl_context_);
[CATransaction commit]; [CATransaction commit];
return submitted; return submitted;
} }

View File

@@ -184,8 +184,7 @@ bool IOSSurfaceSoftware::SubmitFrame(GrContext* context) {
if (platform_views_controller == nullptr) { if (platform_views_controller == nullptr) {
return true; return true;
} }
return platform_views_controller->SubmitFrame(nullptr, fml::WeakPtr<IOSGLContext>(), return platform_views_controller->SubmitFrame(nullptr, nullptr);
fml::WeakPtr<IOSGLContext>());
} }
} // namespace flutter } // namespace flutter

View File

@@ -44,12 +44,10 @@ class PlatformViewIOS final : public PlatformView {
// |PlatformView| // |PlatformView|
void SetSemanticsEnabled(bool enabled) override; void SetSemanticsEnabled(bool enabled) override;
bool HasOnscreenSurface() const;
private: private:
fml::WeakPtr<FlutterViewController> owner_controller_; fml::WeakPtr<FlutterViewController> owner_controller_;
std::unique_ptr<IOSSurface> ios_surface_; std::unique_ptr<IOSSurface> ios_surface_;
std::unique_ptr<IOSGLContext> resource_gl_context_; std::shared_ptr<IOSGLContext> gl_context_;
PlatformMessageRouter platform_message_router_; PlatformMessageRouter platform_message_router_;
std::unique_ptr<AccessibilityBridge> accessibility_bridge_; std::unique_ptr<AccessibilityBridge> accessibility_bridge_;
fml::scoped_nsprotocol<FlutterTextInputPlugin*> text_input_plugin_; fml::scoped_nsprotocol<FlutterTextInputPlugin*> text_input_plugin_;
@@ -77,8 +75,6 @@ class PlatformViewIOS final : public PlatformView {
// |PlatformView| // |PlatformView|
void OnPreEngineRestart() const override; void OnPreEngineRestart() const override;
void NotifyDestroyed() override;
FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS); FML_DISALLOW_COPY_AND_ASSIGN(PlatformViewIOS);
}; };

View File

@@ -23,7 +23,7 @@ PlatformViewIOS::PlatformViewIOS(PlatformView::Delegate& delegate,
flutter::TaskRunners task_runners) flutter::TaskRunners task_runners)
: PlatformView(delegate, std::move(task_runners)) { : PlatformView(delegate, std::move(task_runners)) {
#if !TARGET_IPHONE_SIMULATOR #if !TARGET_IPHONE_SIMULATOR
resource_gl_context_ = std::make_unique<IOSGLContext>(); gl_context_ = std::make_shared<IOSGLContext>();
#endif // !TARGET_IPHONE_SIMULATOR #endif // !TARGET_IPHONE_SIMULATOR
} }
@@ -42,24 +42,16 @@ fml::WeakPtr<FlutterViewController> PlatformViewIOS::GetOwnerViewController() co
return owner_controller_; return owner_controller_;
} }
void PlatformViewIOS::NotifyDestroyed() {
PlatformView::NotifyDestroyed();
ios_surface_.reset();
}
bool PlatformViewIOS::HasOnscreenSurface() const {
return !!ios_surface_;
}
void PlatformViewIOS::SetOwnerViewController(fml::WeakPtr<FlutterViewController> owner_controller) { void PlatformViewIOS::SetOwnerViewController(fml::WeakPtr<FlutterViewController> owner_controller) {
if (ios_surface_ || !owner_controller) { if (ios_surface_ || !owner_controller) {
NotifyDestroyed(); NotifyDestroyed();
ios_surface_.reset();
accessibility_bridge_.reset(); accessibility_bridge_.reset();
} }
owner_controller_ = owner_controller; owner_controller_ = owner_controller;
if (owner_controller_) { if (owner_controller_) {
ios_surface_ = [static_cast<FlutterView*>(owner_controller.get().view) ios_surface_ =
createSurfaceWithResourceGLContext:resource_gl_context_->GetWeakPtr()]; [static_cast<FlutterView*>(owner_controller.get().view) createSurface:gl_context_];
FML_DCHECK(ios_surface_ != nullptr); FML_DCHECK(ios_surface_ != nullptr);
if (accessibility_bridge_) { if (accessibility_bridge_) {
@@ -91,7 +83,7 @@ std::unique_ptr<Surface> PlatformViewIOS::CreateRenderingSurface() {
// |PlatformView| // |PlatformView|
sk_sp<GrContext> PlatformViewIOS::CreateResourceContext() const { sk_sp<GrContext> PlatformViewIOS::CreateResourceContext() const {
if (!resource_gl_context_ || !resource_gl_context_->MakeCurrent()) { if (!gl_context_ || !gl_context_->ResourceMakeCurrent()) {
FML_DLOG(INFO) << "Could not make resource context current on IO thread. " FML_DLOG(INFO) << "Could not make resource context current on IO thread. "
"Async texture uploads will be disabled. On Simulators, " "Async texture uploads will be disabled. On Simulators, "
"this is expected."; "this is expected.";

View File

@@ -27,7 +27,6 @@
24D47D1B230C79840069DD5E /* golden_platform_view_D211AP.png in Resources */ = {isa = PBXBuildFile; fileRef = 24D47D1A230C79840069DD5E /* golden_platform_view_D211AP.png */; }; 24D47D1B230C79840069DD5E /* golden_platform_view_D211AP.png in Resources */ = {isa = PBXBuildFile; fileRef = 24D47D1A230C79840069DD5E /* golden_platform_view_D211AP.png */; };
24D47D1D230CA2700069DD5E /* golden_platform_view_iPhone SE_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 24D47D1C230CA2700069DD5E /* golden_platform_view_iPhone SE_simulator.png */; }; 24D47D1D230CA2700069DD5E /* golden_platform_view_iPhone SE_simulator.png in Resources */ = {isa = PBXBuildFile; fileRef = 24D47D1C230CA2700069DD5E /* golden_platform_view_iPhone SE_simulator.png */; };
24F1FB89230B4579005ACE7C /* TextPlatformView.m in Sources */ = {isa = PBXBuildFile; fileRef = 24F1FB87230B4579005ACE7C /* TextPlatformView.m */; }; 24F1FB89230B4579005ACE7C /* TextPlatformView.m in Sources */ = {isa = PBXBuildFile; fileRef = 24F1FB87230B4579005ACE7C /* TextPlatformView.m */; };
D678B7C82322EFDA00792FDC /* FlutterViewTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D678B7C72322EFDA00792FDC /* FlutterViewTest.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@@ -106,7 +105,6 @@
24D47D1E230CA4480069DD5E /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; }; 24D47D1E230CA4480069DD5E /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
24F1FB87230B4579005ACE7C /* TextPlatformView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TextPlatformView.m; sourceTree = "<group>"; }; 24F1FB87230B4579005ACE7C /* TextPlatformView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TextPlatformView.m; sourceTree = "<group>"; };
24F1FB88230B4579005ACE7C /* TextPlatformView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextPlatformView.h; sourceTree = "<group>"; }; 24F1FB88230B4579005ACE7C /* TextPlatformView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextPlatformView.h; sourceTree = "<group>"; };
D678B7C72322EFDA00792FDC /* FlutterViewTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FlutterViewTest.m; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@@ -178,7 +176,6 @@
children = ( children = (
248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */, 248FDFC322FE7CD0009CC7CD /* FlutterEngineTest.m */,
0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */, 0DB781FC22EA2C0300E9B371 /* FlutterViewControllerTest.m */,
D678B7C72322EFDA00792FDC /* FlutterViewTest.m */,
248D76E522E388380012F0C1 /* Info.plist */, 248D76E522E388380012F0C1 /* Info.plist */,
); );
path = ScenariosTests; path = ScenariosTests;
@@ -352,7 +349,6 @@
files = ( files = (
0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */, 0DB7820222EA493B00E9B371 /* FlutterViewControllerTest.m in Sources */,
248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */, 248FDFC422FE7CD0009CC7CD /* FlutterEngineTest.m in Sources */,
D678B7C82322EFDA00792FDC /* FlutterViewTest.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@@ -1,57 +0,0 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Flutter/Flutter.h>
#import <XCTest/XCTest.h>
#import "AppDelegate.h"
@interface FlutterViewGLContextTest : XCTestCase
@property(nonatomic, strong) FlutterViewController* flutterViewController;
@property(nonatomic, strong) FlutterEngine* flutterEngine;
@end
@implementation FlutterViewGLContextTest
- (void)setUp {
[super setUp];
self.continueAfterFailure = NO;
}
- (void)tearDown {
if (self.flutterViewController) {
[self.flutterViewController removeFromParentViewController];
[self.flutterViewController release];
}
if (self.flutterEngine) {
[self.flutterEngine release];
}
[super tearDown];
}
- (void)testFlutterViewDestroyed {
self.flutterEngine = [[FlutterEngine alloc] initWithName:@"testGL" project:nil];
[self.flutterEngine runWithEntrypoint:nil];
self.flutterViewController = [[FlutterViewController alloc] initWithEngine:self.flutterEngine
nibName:nil
bundle:nil];
AppDelegate* appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate;
UIViewController* rootVC = appDelegate.window.rootViewController;
[rootVC presentViewController:self.flutterViewController animated:NO completion:nil];
// TODO: refactor this to not rely on private test-only APIs
__weak id flutterView = [self.flutterViewController flutterView];
XCTAssertNotNil(flutterView);
XCTAssertTrue([self.flutterViewController hasOnscreenSurface]);
[self.flutterViewController
dismissViewControllerAnimated:NO
completion:^{
__weak id flutterView = [self.flutterViewController flutterView];
XCTAssertNil(flutterView);
XCTAssertFalse([self.flutterViewController hasOnscreenSurface]);
}];
}
@end