-
Notifications
You must be signed in to change notification settings - Fork 6k
WIP: Smooth window resizing on macOS #21110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
|
@@ -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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line can be removed. |
||
| }; | ||
| flutterArguments.custom_task_runners = &custom_task_runners; | ||
|
|
||
|
|
@@ -280,7 +279,8 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint { | |
| } | ||
|
|
||
| [self sendUserLocales]; | ||
| [self updateWindowMetrics]; | ||
|
|
||
| [self.viewController.flutterView start]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to have
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
|
|
||
|
|
@@ -291,7 +291,9 @@ - (void)setViewController:(FlutterViewController*)controller { | |
| [self shutDownEngine]; | ||
| _resourceContext = nil; | ||
| } | ||
| [self updateWindowMetrics]; | ||
| if (_engine) { | ||
| [self.viewController.flutterView start]; | ||
| } | ||
| } | ||
|
|
||
| - (id<FlutterBinaryMessenger>)binaryMessenger { | ||
|
|
@@ -317,6 +319,7 @@ - (NSOpenGLContext*)resourceContext { | |
| return _resourceContext; | ||
| } | ||
|
|
||
| // Must be driven by FlutterView (i.e. [FlutterView start]) | ||
| - (void)updateWindowMetrics { | ||
| if (!_engine) { | ||
| return; | ||
|
|
@@ -334,6 +337,18 @@ - (void)updateWindowMetrics { | |
| FlutterEngineSendWindowMetricsEvent(_engine, &event); | ||
| } | ||
|
|
||
| - (void)scheduleOnRasterTread:(dispatch_block_t)block { | ||
| void* copy = Block_copy((__bridge void*)block); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious, why do we need to copy the block here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| } | ||
|
|
@@ -380,7 +395,7 @@ - (bool)engineCallbackOnPresent { | |
| if (!_mainOpenGLContext) { | ||
| return false; | ||
| } | ||
| [_mainOpenGLContext flushBuffer]; | ||
| [self.viewController.flutterView present]; | ||
| return true; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,11 @@ | |
| */ | ||
| - (void)updateWindowMetrics; | ||
|
|
||
| /** | ||
| * Schedules the block on rater thread. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,32 +7,39 @@ | |
| /** | ||
| * Listener for view resizing. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
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.