Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
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
3 changes: 3 additions & 0 deletions shell/platform/darwin/macos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ source_set("flutter_framework_source") {
sources += _flutter_framework_headers

deps = [
"//flutter/fml:fml",
"//flutter/shell/platform/darwin/common:framework_shared",
"//flutter/shell/platform/embedder:embedder_as_internal_library",
]
Expand All @@ -79,7 +80,9 @@ source_set("flutter_framework_source") {

libs = [
"Cocoa.framework",
"QuartzCore.framework",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: arrange these in alphabetical order.

"CoreVideo.framework",
"IOSurface.framework",
]
}

Expand Down
27 changes: 21 additions & 6 deletions shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ static bool OnPresent(FlutterEngine* engine) {
}

static uint32_t OnFBO(FlutterEngine* engine) {
// There is currently no case where a different FBO is used, so no need to forward.
return 0;
return engine.viewController.flutterView.frameBufferId;
}

static bool OnMakeResourceCurrent(FlutterEngine* engine) {
Expand Down Expand Up @@ -262,7 +261,7 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
const FlutterCustomTaskRunners custom_task_runners = {
.struct_size = sizeof(FlutterCustomTaskRunners),
.platform_task_runner = &cocoa_task_runner_description,
.render_task_runner = &cocoa_task_runner_description,
.render_task_runner = nullptr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line can be removed.

};
flutterArguments.custom_task_runners = &custom_task_runners;

Expand All @@ -280,7 +279,8 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
}

[self sendUserLocales];
[self updateWindowMetrics];

[self.viewController.flutterView start];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to have start rather than doing it in init or ctor for FlutterView?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC start causes flutterView to drive viewport size change. I think I'd prefer that to be separate method rather than doing it from constructor.

return YES;
}

Expand All @@ -291,7 +291,9 @@ - (void)setViewController:(FlutterViewController*)controller {
[self shutDownEngine];
_resourceContext = nil;
}
[self updateWindowMetrics];
if (_engine) {
[self.viewController.flutterView start];
}
}

- (id<FlutterBinaryMessenger>)binaryMessenger {
Expand All @@ -317,6 +319,7 @@ - (NSOpenGLContext*)resourceContext {
return _resourceContext;
}

// Must be driven by FlutterView (i.e. [FlutterView start])
- (void)updateWindowMetrics {
if (!_engine) {
return;
Expand All @@ -334,6 +337,18 @@ - (void)updateWindowMetrics {
FlutterEngineSendWindowMetricsEvent(_engine, &event);
}

- (void)scheduleOnRasterTread:(dispatch_block_t)block {
void* copy = Block_copy((__bridge void*)block);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious, why do we need to copy the block here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocks are by default allocated on stack. It needs to be moved to heap otherwise it will get destroyed on scope exit.

FlutterEnginePostRenderThreadTask(
_engine,
[](void* cb) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rename to callback

dispatch_block_t block = (__bridge dispatch_block_t)cb;
block();
Block_release(block);
},
copy);
}

- (void)sendPointerEvent:(const FlutterPointerEvent&)event {
FlutterEngineSendPointerEvent(_engine, &event, 1);
}
Expand Down Expand Up @@ -380,7 +395,7 @@ - (bool)engineCallbackOnPresent {
if (!_mainOpenGLContext) {
return false;
}
[_mainOpenGLContext flushBuffer];
[self.viewController.flutterView present];
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
*/
- (void)updateWindowMetrics;

/**
* Schedules the block on rater thread.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: rater -> raster

*/
- (void)scheduleOnRasterTread:(nonnull dispatch_block_t)block;

/**
* Dispatches the given pointer event data to engine.
*/
Expand Down
17 changes: 12 additions & 5 deletions shell/platform/darwin/macos/framework/Source/FlutterView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,39 @@
/**
* Listener for view resizing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the doc.

*/
@protocol FlutterViewReshapeListener <NSObject>
@protocol FlutterViewDelegate <NSObject>
/**
* Called when the view's backing store changes size.
*/
- (void)viewDidReshape:(nonnull NSView*)view;
- (void)scheduleOnRasterTread:(nonnull dispatch_block_t)block;

@end

/**
* View capable of acting as a rendering target and input source for the Flutter
* engine.
*/
@interface FlutterView : NSOpenGLView
@interface FlutterView : NSView

@property(readwrite, nonatomic, nonnull) NSOpenGLContext* openGLContext;
@property(readonly, nonatomic) uint32_t frameBufferId;

- (nullable instancetype)initWithFrame:(NSRect)frame
shareContext:(nonnull NSOpenGLContext*)shareContext
reshapeListener:(nonnull id<FlutterViewReshapeListener>)reshapeListener
delegate:(nonnull id<FlutterViewDelegate>)delegate
NS_DESIGNATED_INITIALIZER;

- (nullable instancetype)initWithShareContext:(nonnull NSOpenGLContext*)shareContext
reshapeListener:
(nonnull id<FlutterViewReshapeListener>)reshapeListener;
delegate:(nonnull id<FlutterViewDelegate>)delegate;

- (nullable instancetype)initWithFrame:(NSRect)frameRect
pixelFormat:(nullable NSOpenGLPixelFormat*)format NS_UNAVAILABLE;
- (nonnull instancetype)initWithFrame:(NSRect)frameRect NS_UNAVAILABLE;
- (nullable instancetype)initWithCoder:(nonnull NSCoder*)coder NS_UNAVAILABLE;
- (nonnull instancetype)init NS_UNAVAILABLE;

- (void)start;
- (void)present;

@end
Loading