-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[camera] Convert iOS Obj-C->Dart calls to Pigeon #6568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[camera] Convert iOS Obj-C->Dart calls to Pigeon #6568
Conversation
@@ -30,49 +32,24 @@ extern AVCaptureFlashMode FLTGetAVCaptureFlashModeForFLTFlashMode(FLTFlashMode m | |||
|
|||
#pragma mark - exposure mode | |||
|
|||
/// Represents camera's exposure mode. Mirrors ExposureMode in camera.dart. | |||
typedef NS_ENUM(NSInteger, FLTExposureMode) { |
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.
These enums are no longer needed because we can just use the Pigeon-generated enums instead.
extern FLTExposureMode FLTGetFLTExposureModeForString(NSString *mode); | ||
/// Gets FCPPlatformExposureMode from its string representation. | ||
/// @param mode a string representation of the exposure mode. | ||
extern FCPPlatformExposureMode FCPGetExposureModeForString(NSString *mode); |
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.
These are temporary methods; there are Dart->host calls that send exposure and focus modes, so until I convert those in a follow-up we need to be able to convert method channel strings to the Pigeon enum that replaced the ones removed here.
_camera.dartAPI = [[FCPCameraEventApi alloc] | ||
initWithBinaryMessenger:_messenger | ||
messageChannelSuffix:[NSString stringWithFormat:@"%ld", cameraId]]; | ||
[_camera reportInitializationState]; |
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.
I moved the actual channel invocation into FLTCam
because it seemed strange to have it here when a) the camera instance already has the channel, and b) all of the values here come from the camera instance.
[UIDevice.currentDevice endGeneratingDeviceOrientationNotifications]; | ||
} | ||
|
||
- (void)startOrientationListener { |
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.
I inlined this as a drive-by cleanup because it was only being called from one place, and that was init
, which shouldn't be calling methods.
[NSString stringWithFormat:@"Unknown exposure mode %@", modeStr] | ||
}])); | ||
return; | ||
} |
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.
I'm now preventing this error from being possible on the Dart side (same below).
@@ -552,6 +536,38 @@ class AVFoundationCamera extends CameraPlatform { | |||
return Texture(textureId: cameraId); | |||
} | |||
|
|||
String _serializeFocusMode(FocusMode mode) { |
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.
I added these instead of continuing to use the ones from the platform interface package (the versions without the _
) because having serialization in the platform interface package and deserialization in the implementation package is an anti-pattern since it means changes in one package can break internal communication in another. We created a lot of it by accident during the initial process of federating plugins; Pigeon migration has been eliminating it, but doing it now meant I could remove all the native code that required an "invalid" state for these enums, since I can guarantee within this package that we won't get a state at the native layer that we don't handle.
(These methods will become enum->enum conversion methods instead of enum->string conversion when I finish the Pigeon migration for this package.)
await streamQueue.cancel(); | ||
}); | ||
|
||
test('Should receive resolution changes', () async { |
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.
This and the next test are testing functionality that was dead code. The Dart method call handler handled several messages that are never sent by the native code. It doesn't look like Android uses them either, so I'm guessing it was code mistakenly left in during refactoring in code review of a feature.
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.
Went through a thorough review. Looks pretty clean.
arguments:@{@"orientation" : FLTGetStringForUIDeviceOrientation(orientation)}]; | ||
__weak typeof(self) weakSelf = self; | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
[weakSelf.globalEventAPI |
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.
I vaguely remember there was an effort to make method channel thread safe. what's the progress on that and do we still need to manually dispatch to main in plugin code?
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.
The current state is that replies are thread-safe, but calls that start on the host side still have to be done from the main thread. I don't think there's active work on addressing that part (although I believe it's still something we do eventually want to do).
@interface CameraOrientationTests : XCTestCase | ||
@end | ||
|
||
@implementation CameraOrientationTests | ||
|
||
// Ensure that the given queue and then the main queue have both cycled, to wait for any pending | ||
// async events that may have been bounced between them. | ||
- (void)waitForRoundTripWithQueue:(dispatch_queue_t)queue { |
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.
nice
} | ||
|
||
FLTFocusMode FLTGetFLTFocusModeForString(NSString *mode) { | ||
FCPPlatformFocusMode FCPGetFocusModeForString(NSString *mode) { | ||
if ([mode isEqualToString:@"auto"]) { |
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.
will these hard coded strings be gone eventually after pigeon work is done?
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.
Yes, this is just for the remaining non-Pigeon Dart->host calls.
flutter/packages@0e3809d...88a3a56 2024-04-19 [email protected] [camera] Convert iOS Obj-C->Dart calls to Pigeon (flutter/packages#6568) 2024-04-19 [email protected] [flutter_markdown] Ensure customize nested bullet list style. (flutter/packages#6384) 2024-04-18 [email protected] [ci] Add more dev dependency checks, and fix errors (flutter/packages#6563) 2024-04-18 [email protected] Roll Flutter from 3882afb to fb110b9 (56 revisions) (flutter/packages#6565) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@0e3809d...88a3a56 2024-04-19 [email protected] [camera] Convert iOS Obj-C->Dart calls to Pigeon (flutter/packages#6568) 2024-04-19 [email protected] [flutter_markdown] Ensure customize nested bullet list style. (flutter/packages#6384) 2024-04-18 [email protected] [ci] Add more dev dependency checks, and fix errors (flutter/packages#6563) 2024-04-18 [email protected] Roll Flutter from 3882afb to fb110b9 (56 revisions) (flutter/packages#6565) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Converts all of the Obj-C -> Dart calls to Pigeon, using the new suffix-based Pigeon API instantiation feature. This required decentralizing some threading code slightly: since method channel calls only involve one method (due to the lack of strong types), a wrapper that automatically did thread bouncing was feasible, but with Pigeon it's not since a wrapper would have to duplicate the entire API surface, and that's more work than just doing the dispatches at the call site. Part of flutter/flutter#117905
Converts all of the Obj-C -> Dart calls to Pigeon, using the new suffix-based Pigeon API instantiation feature. This required decentralizing some threading code slightly: since method channel calls only involve one method (due to the lack of strong types), a wrapper that automatically did thread bouncing was feasible, but with Pigeon it's not since a wrapper would have to duplicate the entire API surface, and that's more work than just doing the dispatches at the call site. Part of flutter/flutter#117905
…7857) Part of the effort to transition to typesafe implementations for platform calls. Android analog to #6568 Part of flutter/flutter#117905 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.) - [ ] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [x] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version [following repository CHANGELOG style]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style [exempt from CHANGELOG changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog [test-exempt]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
Converts all of the Obj-C -> Dart calls to Pigeon, using the new suffix-based Pigeon API instantiation feature.
This required decentralizing some threading code slightly: since method channel calls only involve one method (due to the lack of strong types), a wrapper that automatically did thread bouncing was feasible, but with Pigeon it's not since a wrapper would have to duplicate the entire API surface, and that's more work than just doing the dispatches at the call site.
Part of flutter/flutter#117905
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).