Skip to content

Commit 65342cb

Browse files
committed
Revert "Manage resource and onscreen contexts using separate IOSGLContext objects (flutter#12277)"
This reverts commit 5a8da65.
1 parent da71c38 commit 65342cb

15 files changed

+83
-150
lines changed

shell/platform/darwin/ios/framework/Source/FlutterOverlayView.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@
2424

2525
- (instancetype)init NS_DESIGNATED_INITIALIZER;
2626
- (instancetype)initWithContentsScale:(CGFloat)contentsScale;
27-
- (std::unique_ptr<flutter::IOSSurface>)
28-
createSurfaceWithOnscreenGLContext:(fml::WeakPtr<flutter::IOSGLContext>)onscreenGLContext
29-
resourceGLContext:(fml::WeakPtr<flutter::IOSGLContext>)resourceGLContext;
27+
- (std::unique_ptr<flutter::IOSSurface>)createSurface:
28+
(std::shared_ptr<flutter::IOSGLContext>)gl_context;
3029

3130
@end
3231

shell/platform/darwin/ios/framework/Source/FlutterOverlayView.mm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,15 @@ + (Class)layerClass {
7878
#endif // TARGET_IPHONE_SIMULATOR
7979
}
8080

81-
- (std::unique_ptr<flutter::IOSSurface>)
82-
createSurfaceWithOnscreenGLContext:(fml::WeakPtr<flutter::IOSGLContext>)onscreenGLContext
83-
resourceGLContext:(fml::WeakPtr<flutter::IOSGLContext>)resourceGLContext {
81+
- (std::unique_ptr<flutter::IOSSurface>)createSurface:
82+
(std::shared_ptr<flutter::IOSGLContext>)gl_context {
8483
if ([self.layer isKindOfClass:[CAEAGLLayer class]]) {
8584
fml::scoped_nsobject<CAEAGLLayer> eagl_layer(
8685
reinterpret_cast<CAEAGLLayer*>([self.layer retain]));
8786
if (@available(iOS 9.0, *)) {
8887
eagl_layer.get().presentsWithTransaction = YES;
8988
}
90-
return std::make_unique<flutter::IOSSurfaceGL>(std::move(eagl_layer), onscreenGLContext,
91-
resourceGLContext);
89+
return std::make_unique<flutter::IOSSurfaceGL>(std::move(eagl_layer), gl_context);
9290
#if FLUTTER_SHELL_ENABLE_METAL
9391
} else if ([self.layer isKindOfClass:[CAMetalLayer class]]) {
9492
fml::scoped_nsobject<CAMetalLayer> metalLayer(

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews.mm

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,12 @@
363363
}
364364

365365
bool FlutterPlatformViewsController::SubmitFrame(GrContext* gr_context,
366-
fml::WeakPtr<IOSGLContext> onscreen_gl_context,
367-
fml::WeakPtr<IOSGLContext> resource_gl_context) {
366+
std::shared_ptr<IOSGLContext> gl_context) {
368367
DisposeViews();
369368

370369
bool did_submit = true;
371370
for (int64_t view_id : composition_order_) {
372-
EnsureOverlayInitialized(view_id, onscreen_gl_context, resource_gl_context, gr_context);
371+
EnsureOverlayInitialized(view_id, std::move(gl_context), gr_context);
373372
auto frame = overlays_[view_id]->surface->AcquireFrame(frame_size_);
374373
SkCanvas* canvas = frame->SkiaCanvas();
375374
canvas->drawPicture(picture_recorders_[view_id]->finishRecordingAsPicture());
@@ -453,8 +452,7 @@
453452

454453
void FlutterPlatformViewsController::EnsureOverlayInitialized(
455454
int64_t overlay_id,
456-
fml::WeakPtr<IOSGLContext> onscreen_gl_context,
457-
fml::WeakPtr<IOSGLContext> resource_gl_context,
455+
std::shared_ptr<IOSGLContext> gl_context,
458456
GrContext* gr_context) {
459457
FML_DCHECK(flutter_view_);
460458

@@ -470,9 +468,7 @@
470468
overlay_view.get().frame = flutter_view_.get().bounds;
471469
overlay_view.get().autoresizingMask =
472470
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
473-
std::unique_ptr<IOSSurface> ios_surface = [overlay_view.get()
474-
createSurfaceWithOnscreenGLContext:fml::WeakPtr<flutter::IOSGLContext>()
475-
resourceGLContext:fml::WeakPtr<flutter::IOSGLContext>()];
471+
std::unique_ptr<IOSSurface> ios_surface = [overlay_view.get() createSurface:nil];
476472
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface();
477473
overlays_[overlay_id] = std::make_unique<FlutterPlatformViewLayer>(
478474
std::move(overlay_view), std::move(ios_surface), std::move(surface));
@@ -497,8 +493,7 @@
497493
overlay_view.get().autoresizingMask =
498494
(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
499495
std::unique_ptr<IOSSurface> ios_surface =
500-
[overlay_view.get() createSurfaceWithOnscreenGLContext:std::move(onscreen_gl_context)
501-
resourceGLContext:std::move(resource_gl_context)];
496+
[overlay_view.get() createSurface:std::move(gl_context)];
502497
std::unique_ptr<Surface> surface = ios_surface->CreateGPUSurface(gr_context);
503498
overlays_[overlay_id] = std::make_unique<FlutterPlatformViewLayer>(
504499
std::move(overlay_view), std::move(ios_surface), std::move(surface));

shell/platform/darwin/ios/framework/Source/FlutterPlatformViews_Internal.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ class FlutterPlatformViewsController {
100100
// Discards all platform views instances and auxiliary resources.
101101
void Reset();
102102

103-
bool SubmitFrame(GrContext* gr_context,
104-
fml::WeakPtr<IOSGLContext> onscreen_gl_context,
105-
fml::WeakPtr<IOSGLContext> resource_gl_context);
103+
bool SubmitFrame(GrContext* gr_context, std::shared_ptr<IOSGLContext> gl_context);
106104

107105
void OnMethodCall(FlutterMethodCall* call, FlutterResult& result);
108106

@@ -164,8 +162,7 @@ class FlutterPlatformViewsController {
164162
// Dispose the views in `views_to_dispose_`.
165163
void DisposeViews();
166164
void EnsureOverlayInitialized(int64_t overlay_id,
167-
fml::WeakPtr<IOSGLContext> onscreen_gl_context,
168-
fml::WeakPtr<IOSGLContext> resource_gl_context,
165+
std::shared_ptr<IOSGLContext> gl_context,
169166
GrContext* gr_context);
170167

171168
// This will return true after pre-roll if any of the embedded views

shell/platform/darwin/ios/framework/Source/FlutterView.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434
- (instancetype)initWithDelegate:(id<FlutterViewEngineDelegate>)delegate
3535
opaque:(BOOL)opaque NS_DESIGNATED_INITIALIZER;
36-
- (std::unique_ptr<flutter::IOSSurface>)createSurfaceWithResourceGLContext:
37-
(fml::WeakPtr<flutter::IOSGLContext>)resourceGLContext;
36+
- (std::unique_ptr<flutter::IOSSurface>)createSurface:
37+
(std::shared_ptr<flutter::IOSGLContext>)context;
3838

3939
@end
4040

shell/platform/darwin/ios/framework/Source/FlutterView.mm

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "flutter/shell/common/platform_view.h"
1414
#include "flutter/shell/common/rasterizer.h"
1515
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
16-
#include "flutter/shell/platform/darwin/ios/ios_gl_context.h"
1716
#include "flutter/shell/platform/darwin/ios/ios_surface_gl.h"
1817
#include "flutter/shell/platform/darwin/ios/ios_surface_software.h"
1918
#include "third_party/skia/include/utils/mac/SkCGUtils.h"
@@ -22,10 +21,9 @@
2221
#include "flutter/shell/platform/darwin/ios/ios_surface_metal.h"
2322
#endif // FLUTTER_SHELL_ENABLE_METAL
2423

25-
@implementation FlutterView {
26-
id<FlutterViewEngineDelegate> _delegate;
27-
std::unique_ptr<flutter::IOSGLContext> _onscreenGLContext;
28-
}
24+
@implementation FlutterView
25+
26+
id<FlutterViewEngineDelegate> _delegate;
2927

3028
- (instancetype)init {
3129
@throw([NSException exceptionWithName:@"FlutterView must initWithDelegate"
@@ -95,14 +93,8 @@ + (Class)layerClass {
9593
#endif // TARGET_IPHONE_SIMULATOR
9694
}
9795

98-
- (std::unique_ptr<flutter::IOSSurface>)createSurfaceWithResourceGLContext:
99-
(fml::WeakPtr<flutter::IOSGLContext>)resourceGLContext {
100-
#if !TARGET_IPHONE_SIMULATOR
101-
if (!_onscreenGLContext) {
102-
_onscreenGLContext = resourceGLContext->MakeSharedContext();
103-
}
104-
#endif // !TARGET_IPHONE_SIMULATOR
105-
96+
- (std::unique_ptr<flutter::IOSSurface>)createSurface:
97+
(std::shared_ptr<flutter::IOSGLContext>)context {
10698
if ([self.layer isKindOfClass:[CAEAGLLayer class]]) {
10799
fml::scoped_nsobject<CAEAGLLayer> eagl_layer(
108100
reinterpret_cast<CAEAGLLayer*>([self.layer retain]));
@@ -113,9 +105,8 @@ + (Class)layerClass {
113105
eagl_layer.get().presentsWithTransaction = YES;
114106
}
115107
}
116-
return std::make_unique<flutter::IOSSurfaceGL>(
117-
_onscreenGLContext->GetWeakPtr(), std::move(resourceGLContext), std::move(eagl_layer),
118-
[_delegate platformViewsController]);
108+
return std::make_unique<flutter::IOSSurfaceGL>(context, std::move(eagl_layer),
109+
[_delegate platformViewsController]);
119110
#if FLUTTER_SHELL_ENABLE_METAL
120111
} else if ([self.layer isKindOfClass:[CAMetalLayer class]]) {
121112
fml::scoped_nsobject<CAMetalLayer> metalLayer(

shell/platform/darwin/ios/ios_gl_context.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,30 @@
1313
#include "flutter/fml/macros.h"
1414
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
1515
#include "flutter/shell/common/platform_view.h"
16+
#include "ios_gl_render_target.h"
1617

1718
namespace flutter {
1819

1920
class IOSGLContext {
2021
public:
2122
IOSGLContext();
22-
IOSGLContext(EAGLSharegroup* sharegroup);
2323

2424
~IOSGLContext();
2525

26+
std::unique_ptr<IOSGLRenderTarget> CreateRenderTarget(
27+
fml::scoped_nsobject<CAEAGLLayer> layer);
28+
2629
bool MakeCurrent();
2730

28-
bool BindRenderbufferStorage(fml::scoped_nsobject<CAEAGLLayer> layer);
31+
bool ResourceMakeCurrent();
2932

3033
sk_sp<SkColorSpace> ColorSpace() const { return color_space_; }
3134

32-
std::unique_ptr<IOSGLContext> MakeSharedContext();
33-
34-
fml::WeakPtr<IOSGLContext> GetWeakPtr();
35-
3635
private:
3736
fml::scoped_nsobject<EAGLContext> context_;
37+
fml::scoped_nsobject<EAGLContext> resource_context_;
3838
sk_sp<SkColorSpace> color_space_;
3939

40-
std::unique_ptr<fml::WeakPtrFactory<IOSGLContext>> weak_factory_;
41-
4240
FML_DISALLOW_COPY_AND_ASSIGN(IOSGLContext);
4341
};
4442

shell/platform/darwin/ios/ios_gl_context.mm

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212

1313
namespace flutter {
1414

15-
IOSGLContext::IOSGLContext() : IOSGLContext(nullptr) {}
16-
17-
IOSGLContext::IOSGLContext(EAGLSharegroup* sharegroup)
18-
: weak_factory_(std::make_unique<fml::WeakPtrFactory<IOSGLContext>>(this)) {
19-
context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3
20-
sharegroup:sharegroup]);
21-
22-
if (!context_) {
15+
IOSGLContext::IOSGLContext() {
16+
resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]);
17+
if (resource_context_ != nullptr) {
18+
context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3
19+
sharegroup:resource_context_.get().sharegroup]);
20+
} else {
21+
resource_context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]);
2322
context_.reset([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2
24-
sharegroup:sharegroup]);
23+
sharegroup:resource_context_.get().sharegroup]);
2524
}
2625

2726
// TODO:
@@ -45,22 +44,20 @@
4544
}
4645
}
4746

48-
fml::WeakPtr<IOSGLContext> IOSGLContext::GetWeakPtr() {
49-
return weak_factory_->GetWeakPtr();
50-
}
47+
IOSGLContext::~IOSGLContext() = default;
5148

52-
bool IOSGLContext::BindRenderbufferStorage(fml::scoped_nsobject<CAEAGLLayer> layer) {
53-
return [context_.get() renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer.get()];
49+
std::unique_ptr<IOSGLRenderTarget> IOSGLContext::CreateRenderTarget(
50+
fml::scoped_nsobject<CAEAGLLayer> layer) {
51+
return std::make_unique<IOSGLRenderTarget>(std::move(layer), context_.get(),
52+
resource_context_.get());
5453
}
5554

56-
IOSGLContext::~IOSGLContext() = default;
57-
5855
bool IOSGLContext::MakeCurrent() {
5956
return [EAGLContext setCurrentContext:context_.get()];
6057
}
6158

62-
std::unique_ptr<IOSGLContext> IOSGLContext::MakeSharedContext() {
63-
return std::make_unique<IOSGLContext>(context_.get().sharegroup);
59+
bool IOSGLContext::ResourceMakeCurrent() {
60+
return [EAGLContext setCurrentContext:resource_context_.get()];
6461
}
6562

6663
} // namespace flutter

shell/platform/darwin/ios/ios_gl_render_target.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
#include "flutter/fml/macros.h"
1414
#include "flutter/fml/platform/darwin/scoped_nsobject.h"
1515
#include "flutter/shell/common/platform_view.h"
16-
#include "flutter/shell/platform/darwin/ios/ios_gl_context.h"
1716

1817
namespace flutter {
1918

2019
class IOSGLRenderTarget {
2120
public:
2221
IOSGLRenderTarget(fml::scoped_nsobject<CAEAGLLayer> layer,
23-
fml::WeakPtr<IOSGLContext> onscreen_context,
24-
fml::WeakPtr<IOSGLContext> resource_context);
22+
EAGLContext* context,
23+
EAGLContext* resource_context);
2524

2625
~IOSGLRenderTarget();
2726

@@ -41,8 +40,8 @@ class IOSGLRenderTarget {
4140

4241
private:
4342
fml::scoped_nsobject<CAEAGLLayer> layer_;
44-
fml::WeakPtr<IOSGLContext> onscreen_gl_context_;
45-
fml::WeakPtr<IOSGLContext> resource_gl_context_;
43+
fml::scoped_nsobject<EAGLContext> context_;
44+
fml::scoped_nsobject<EAGLContext> resource_context_;
4645
GLuint framebuffer_;
4746
GLuint colorbuffer_;
4847
GLint storage_size_width_;

shell/platform/darwin/ios/ios_gl_render_target.mm

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@
1111
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
1212

1313
namespace flutter {
14+
1415
IOSGLRenderTarget::IOSGLRenderTarget(fml::scoped_nsobject<CAEAGLLayer> layer,
15-
fml::WeakPtr<IOSGLContext> onscreen_gl_context,
16-
fml::WeakPtr<IOSGLContext> resource_gl_context)
16+
EAGLContext* context,
17+
EAGLContext* resource_context)
1718
: layer_(std::move(layer)),
18-
onscreen_gl_context_(std::move(onscreen_gl_context)),
19-
resource_gl_context_(std::move(resource_gl_context)),
19+
context_([context retain]),
20+
resource_context_([resource_context retain]),
2021
framebuffer_(GL_NONE),
2122
colorbuffer_(GL_NONE),
2223
storage_size_width_(0),
2324
storage_size_height_(0),
2425
valid_(false) {
2526
FML_DCHECK(layer_ != nullptr);
26-
FML_DCHECK(onscreen_gl_context_);
27-
FML_DCHECK(resource_gl_context_);
27+
FML_DCHECK(context_ != nullptr);
28+
FML_DCHECK(resource_context_ != nullptr);
2829

29-
bool context_current = onscreen_gl_context_->MakeCurrent();
30+
bool context_current = [EAGLContext setCurrentContext:context_];
3031

3132
FML_DCHECK(context_current);
3233
FML_DCHECK(glGetError() == GL_NO_ERROR);
@@ -62,7 +63,7 @@
6263

6364
IOSGLRenderTarget::~IOSGLRenderTarget() {
6465
EAGLContext* context = EAGLContext.currentContext;
65-
onscreen_gl_context_->MakeCurrent();
66+
[EAGLContext setCurrentContext:context_];
6667
FML_DCHECK(glGetError() == GL_NO_ERROR);
6768

6869
// Deletes on GL_NONEs are ignored
@@ -104,7 +105,7 @@
104105

105106
FML_DCHECK(glGetError() == GL_NO_ERROR);
106107

107-
if (!onscreen_gl_context_->MakeCurrent()) {
108+
if (![EAGLContext setCurrentContext:context_]) {
108109
return false;
109110
}
110111

@@ -115,7 +116,7 @@
115116
glBindRenderbuffer(GL_RENDERBUFFER, colorbuffer_);
116117
FML_DCHECK(glGetError() == GL_NO_ERROR);
117118

118-
if (!onscreen_gl_context_->BindRenderbufferStorage(layer_)) {
119+
if (![context_.get() renderbufferStorage:GL_RENDERBUFFER fromDrawable:layer_.get()]) {
119120
return false;
120121
}
121122

@@ -132,11 +133,11 @@
132133
}
133134

134135
bool IOSGLRenderTarget::MakeCurrent() {
135-
return UpdateStorageSizeIfNecessary() && onscreen_gl_context_->MakeCurrent();
136+
return UpdateStorageSizeIfNecessary() && [EAGLContext setCurrentContext:context_.get()];
136137
}
137138

138139
bool IOSGLRenderTarget::ResourceMakeCurrent() {
139-
return resource_gl_context_->MakeCurrent();
140+
return [EAGLContext setCurrentContext:resource_context_.get()];
140141
}
141142

142143
} // namespace flutter

0 commit comments

Comments
 (0)