Rename default views to implicit views (flutter/engine#43364)
This PR renames a number of internal variables from "default view ID" to "implicit view ID", as we have pretty much settled on naming this mechanism. Some docs are also fixed accordingly. ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See [testing the engine] for instructions on writing and running engine tests. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I signed the [CLA]. - [ ] 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/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
namespace flutter {
|
||||
|
||||
const uint64_t kFlutterDefaultViewId = 0llu;
|
||||
const uint64_t kFlutterImplicitViewId = 0llu;
|
||||
|
||||
RuntimeController::RuntimeController(RuntimeDelegate& p_client,
|
||||
const TaskRunners& task_runners)
|
||||
@@ -320,7 +320,7 @@ void RuntimeController::ScheduleFrame() {
|
||||
// |PlatformConfigurationClient|
|
||||
void RuntimeController::Render(Scene* scene) {
|
||||
// TODO(dkwingsmt): Currently only supports a single window.
|
||||
int64_t view_id = kFlutterDefaultViewId;
|
||||
int64_t view_id = kFlutterImplicitViewId;
|
||||
auto window =
|
||||
UIDartState::Current()->platform_configuration()->get_window(view_id);
|
||||
if (window == nullptr) {
|
||||
|
||||
@@ -36,11 +36,13 @@ FLUTTER_DARWIN_EXPORT
|
||||
@property(nonnull, readonly) id<FlutterTextureRegistry> textures;
|
||||
|
||||
/**
|
||||
* The default view displaying Flutter content.
|
||||
* The view displaying Flutter content.
|
||||
*
|
||||
* This property is provided for backwards compatibility for apps
|
||||
* that assume a single view. This will eventually be replaced by
|
||||
* a multi-view API variant.
|
||||
*
|
||||
* This method may return |nil|, for instance in a headless environment.
|
||||
*
|
||||
* The default view is a special view operated by single-view APIs.
|
||||
*/
|
||||
@property(nullable, readonly) NSView* view;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ bool FlutterCompositor::CreateBackingStore(const FlutterBackingStoreConfig* conf
|
||||
// TODO(dkwingsmt): This class only supports single-view for now. As more
|
||||
// classes are gradually converted to multi-view, it should get the view ID
|
||||
// from somewhere.
|
||||
FlutterView* view = [view_provider_ viewForId:kFlutterDefaultViewId];
|
||||
FlutterView* view = [view_provider_ viewForId:kFlutterImplicitViewId];
|
||||
if (!view) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -12,27 +12,27 @@
|
||||
#import "flutter/testing/testing.h"
|
||||
|
||||
@interface FlutterViewMockProvider : NSObject <FlutterViewProvider> {
|
||||
FlutterView* _defaultView;
|
||||
FlutterView* _implicitView;
|
||||
}
|
||||
/**
|
||||
* Create a FlutterViewMockProvider with the provided view as the default view.
|
||||
* Create a FlutterViewMockProvider with the provided view as the implicit view.
|
||||
*/
|
||||
- (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view;
|
||||
- (nonnull instancetype)initWithImplicitView:(nonnull FlutterView*)view;
|
||||
@end
|
||||
|
||||
@implementation FlutterViewMockProvider
|
||||
|
||||
- (nonnull instancetype)initWithDefaultView:(nonnull FlutterView*)view {
|
||||
- (nonnull instancetype)initWithImplicitView:(nonnull FlutterView*)view {
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_defaultView = view;
|
||||
_implicitView = view;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable FlutterView*)viewForId:(FlutterViewId)viewId {
|
||||
if (viewId == kFlutterDefaultViewId) {
|
||||
return _defaultView;
|
||||
if (viewId == kFlutterImplicitViewId) {
|
||||
return _implicitView;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ id<FlutterViewProvider> MockViewProvider(PresentBlock onPresent = nil) {
|
||||
|
||||
OCMStub([surfaceMock asFlutterMetalTexture]).andReturn(texture);
|
||||
|
||||
return [[FlutterViewMockProvider alloc] initWithDefaultView:viewMock];
|
||||
return [[FlutterViewMockProvider alloc] initWithImplicitView:viewMock];
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -131,7 +131,7 @@ TEST(FlutterCompositorTest, TestPresent) {
|
||||
}};
|
||||
const FlutterLayer* layers_ptr = layers;
|
||||
|
||||
macos_compositor->Present(kFlutterDefaultViewId, &layers_ptr, 1);
|
||||
macos_compositor->Present(kFlutterImplicitViewId, &layers_ptr, 1);
|
||||
|
||||
ASSERT_EQ(presentedSurfaces.count, 1ul);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ constexpr char kTextPlainFormat[] = "text/plain";
|
||||
* An internal method that adds the view controller with the given ID.
|
||||
*
|
||||
* This method assigns the controller with the ID, puts the controller into the
|
||||
* map, and does assertions related to the default view ID.
|
||||
* map, and does assertions related to the implicit view ID.
|
||||
*/
|
||||
- (void)registerViewController:(FlutterViewController*)controller forId:(FlutterViewId)viewId;
|
||||
|
||||
@@ -296,7 +296,7 @@ constexpr char kTextPlainFormat[] = "text/plain";
|
||||
}
|
||||
|
||||
- (NSView*)view {
|
||||
return [self viewForId:kFlutterDefaultViewId];
|
||||
return [self viewForId:kFlutterImplicitViewId];
|
||||
}
|
||||
|
||||
- (NSView*)viewForId:(FlutterViewId)viewId {
|
||||
@@ -422,9 +422,9 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
[_isResponseValid addObject:@YES];
|
||||
_terminationHandler = [[FlutterEngineTerminationHandler alloc] initWithEngine:self
|
||||
terminator:nil];
|
||||
// kFlutterDefaultViewId is reserved for the default view.
|
||||
// kFlutterImplicitViewId is reserved for the implicit view.
|
||||
// All IDs above it are for regular views.
|
||||
_nextViewId = kFlutterDefaultViewId + 1;
|
||||
_nextViewId = kFlutterImplicitViewId + 1;
|
||||
|
||||
_embedderAPI.struct_size = sizeof(FlutterEngineProcTable);
|
||||
FlutterEngineGetProcAddresses(&_embedderAPI);
|
||||
@@ -506,10 +506,10 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
flutterArguments.update_semantics_callback2 = [](const FlutterSemanticsUpdate2* update,
|
||||
void* user_data) {
|
||||
// TODO(dkwingsmt): This callback only supports single-view, therefore it
|
||||
// only operates on the default view. To support multi-view, we need a
|
||||
// only operates on the implicit view. To support multi-view, we need a
|
||||
// way to pass in the ID (probably through FlutterSemanticsUpdate).
|
||||
FlutterEngine* engine = (__bridge FlutterEngine*)user_data;
|
||||
[[engine viewControllerForId:kFlutterDefaultViewId] updateSemantics:update];
|
||||
[[engine viewControllerForId:kFlutterImplicitViewId] updateSemantics:update];
|
||||
};
|
||||
flutterArguments.custom_dart_entrypoint = entrypoint.UTF8String;
|
||||
flutterArguments.shutdown_dart_vm_when_done = true;
|
||||
@@ -645,7 +645,7 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
|
||||
- (void)setViewController:(FlutterViewController*)controller {
|
||||
FlutterViewController* currentController =
|
||||
[_viewControllers objectForKey:@(kFlutterDefaultViewId)];
|
||||
[_viewControllers objectForKey:@(kFlutterImplicitViewId)];
|
||||
if (currentController == controller) {
|
||||
// From nil to nil, or from non-nil to the same controller.
|
||||
return;
|
||||
@@ -658,26 +658,26 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
@"If you wanted to create an FlutterViewController and set it to an existing engine, "
|
||||
@"you should use FlutterViewController#init(engine:, nibName, bundle:) instead.",
|
||||
controller.engine);
|
||||
[self registerViewController:controller forId:kFlutterDefaultViewId];
|
||||
[self registerViewController:controller forId:kFlutterImplicitViewId];
|
||||
} else if (currentController != nil && controller == nil) {
|
||||
NSAssert(currentController.viewId == kFlutterDefaultViewId,
|
||||
NSAssert(currentController.viewId == kFlutterImplicitViewId,
|
||||
@"The default controller has an unexpected ID %llu", currentController.viewId);
|
||||
// From non-nil to nil.
|
||||
[self deregisterViewControllerForId:kFlutterDefaultViewId];
|
||||
[self deregisterViewControllerForId:kFlutterImplicitViewId];
|
||||
[self shutDownIfNeeded];
|
||||
} else {
|
||||
// From non-nil to a different non-nil view controller.
|
||||
NSAssert(NO,
|
||||
@"Failed to set view controller to the engine: "
|
||||
@"The engine already has a default view controller %@. "
|
||||
@"If you wanted to make the default view render in a different window, "
|
||||
@"The engine already has an implicit view controller %@. "
|
||||
@"If you wanted to make the implicit view render in a different window, "
|
||||
@"you should attach the current view controller to the window instead.",
|
||||
[_viewControllers objectForKey:@(kFlutterDefaultViewId)]);
|
||||
[_viewControllers objectForKey:@(kFlutterImplicitViewId)]);
|
||||
}
|
||||
}
|
||||
|
||||
- (FlutterViewController*)viewController {
|
||||
return [self viewControllerForId:kFlutterDefaultViewId];
|
||||
return [self viewControllerForId:kFlutterImplicitViewId];
|
||||
}
|
||||
|
||||
- (FlutterCompositor*)createFlutterCompositor {
|
||||
@@ -705,9 +705,9 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
void* user_data //
|
||||
) {
|
||||
// TODO(dkwingsmt): This callback only supports single-view, therefore it
|
||||
// only operates on the default view. To support multi-view, we need a new
|
||||
// only operates on the implicit view. To support multi-view, we need a new
|
||||
// callback that also receives a view ID.
|
||||
return reinterpret_cast<flutter::FlutterCompositor*>(user_data)->Present(kFlutterDefaultViewId,
|
||||
return reinterpret_cast<flutter::FlutterCompositor*>(user_data)->Present(kFlutterImplicitViewId,
|
||||
layers, layers_count);
|
||||
};
|
||||
|
||||
@@ -725,7 +725,7 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
#pragma mark - Framework-internal methods
|
||||
|
||||
- (void)addViewController:(FlutterViewController*)controller {
|
||||
[self registerViewController:controller forId:kFlutterDefaultViewId];
|
||||
[self registerViewController:controller forId:kFlutterImplicitViewId];
|
||||
}
|
||||
|
||||
- (void)removeViewController:(nonnull FlutterViewController*)viewController {
|
||||
@@ -812,7 +812,7 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
}
|
||||
|
||||
- (void)updateWindowMetricsForViewController:(FlutterViewController*)viewController {
|
||||
if (viewController.viewId != kFlutterDefaultViewId) {
|
||||
if (viewController.viewId != kFlutterImplicitViewId) {
|
||||
// TODO(dkwingsmt): The embedder API only supports single-view for now. As
|
||||
// embedder APIs are converted to multi-view, this method should support any
|
||||
// views.
|
||||
@@ -1078,7 +1078,7 @@ static void OnPlatformMessage(const FlutterPlatformMessage* message, FlutterEngi
|
||||
- (void)announceAccessibilityMessage:(NSString*)message
|
||||
withPriority:(NSAccessibilityPriorityLevel)priority {
|
||||
NSAccessibilityPostNotificationWithUserInfo(
|
||||
[self viewControllerForId:kFlutterDefaultViewId].flutterView,
|
||||
[self viewControllerForId:kFlutterImplicitViewId].flutterView,
|
||||
NSAccessibilityAnnouncementRequestedNotification,
|
||||
@{NSAccessibilityAnnouncementKey : message, NSAccessibilityPriorityKey : @(priority)});
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
// CREATE_NATIVE_ENTRY and MOCK_ENGINE_PROC are leaky by design
|
||||
// NOLINTBEGIN(clang-analyzer-core.StackAddressEscape)
|
||||
|
||||
constexpr int64_t kDefaultViewId = 0ll;
|
||||
constexpr int64_t kImplicitViewId = 0ll;
|
||||
|
||||
@interface FlutterEngine (Test)
|
||||
/**
|
||||
@@ -354,7 +354,7 @@ TEST_F(FlutterEngineTest, CanToggleAccessibilityWhenHeadless) {
|
||||
FlutterSemanticsNode2* nodes[] = {&root, &child1};
|
||||
update.nodes = nodes;
|
||||
update.custom_action_count = 0;
|
||||
// This call updates semantics for the default view, which does not exist,
|
||||
// This call updates semantics for the implicit view, which does not exist,
|
||||
// and therefore this call is invalid. But the engine should not crash.
|
||||
update_semantics_callback(&update, (__bridge void*)engine);
|
||||
|
||||
@@ -632,7 +632,7 @@ TEST_F(FlutterEngineTest, ThreadSynchronizerNotBlockingRasterThreadAfterShutdown
|
||||
[threadSynchronizer shutdown];
|
||||
|
||||
std::thread rasterThread([&threadSynchronizer] {
|
||||
[threadSynchronizer performCommitForView:kDefaultViewId
|
||||
[threadSynchronizer performCommitForView:kImplicitViewId
|
||||
size:CGSizeMake(100, 100)
|
||||
notify:^{
|
||||
}];
|
||||
|
||||
@@ -115,7 +115,7 @@ typedef NS_ENUM(NSInteger, FlutterAppExitResponse) {
|
||||
*
|
||||
* Practically, since FlutterEngine can only be attached with one controller,
|
||||
* the given controller, if successfully attached, will always have the default
|
||||
* view ID kFlutterDefaultViewId.
|
||||
* view ID kFlutterImplicitViewId.
|
||||
*
|
||||
* The engine holds a weak reference to the attached view controller.
|
||||
*
|
||||
@@ -127,11 +127,11 @@ typedef NS_ENUM(NSInteger, FlutterAppExitResponse) {
|
||||
/**
|
||||
* Dissociate the given view controller from this engine.
|
||||
*
|
||||
* Practically, since FlutterEngine can only be attached with one controller,
|
||||
* the given controller must be the default view controller.
|
||||
*
|
||||
* If the view controller is not associated with this engine, this call throws an
|
||||
* assertion.
|
||||
*
|
||||
* Practically, since FlutterEngine can only be attached with one controller for
|
||||
* now, the given controller must be the current view controller.
|
||||
*/
|
||||
- (void)removeViewController:(FlutterViewController*)viewController;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ typedef int64_t FlutterViewId;
|
||||
* backward compatibility, single-view APIs will always operate on the view with
|
||||
* this ID. Also, the first view assigned to the engine will also have this ID.
|
||||
*/
|
||||
constexpr FlutterViewId kFlutterDefaultViewId = 0ll;
|
||||
constexpr FlutterViewId kFlutterImplicitViewId = 0ll;
|
||||
|
||||
/**
|
||||
* Listener for view resizing.
|
||||
|
||||
@@ -27,7 +27,7 @@ TEST(FlutterViewEngineProviderUnittests, GetViewReturnsTheCorrectView) {
|
||||
.andDo(^(NSInvocation* invocation) {
|
||||
FlutterViewId viewId;
|
||||
[invocation getArgument:&viewId atIndex:2];
|
||||
if (viewId == kFlutterDefaultViewId) {
|
||||
if (viewId == kFlutterImplicitViewId) {
|
||||
if (mockFlutterViewController != nil) {
|
||||
[invocation setReturnValue:&mockFlutterViewController];
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#import "flutter/testing/testing.h"
|
||||
|
||||
constexpr int64_t kDefaultViewId = 0ll;
|
||||
constexpr int64_t kImplicitViewId = 0ll;
|
||||
|
||||
@interface TestReshapeListener : NSObject <FlutterViewReshapeListener>
|
||||
|
||||
@@ -30,6 +30,6 @@ TEST(FlutterView, ShouldInheritContentsScaleReturnsYes) {
|
||||
commandQueue:queue
|
||||
reshapeListener:listener
|
||||
threadSynchronizer:threadSynchronizer
|
||||
viewId:kDefaultViewId];
|
||||
viewId:kImplicitViewId];
|
||||
EXPECT_EQ([view layer:view.layer shouldInheritContentsScale:3.0 fromWindow:view.window], YES);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user